From b179380eda6bf79f54d61b22908fc17ac964b883 Mon Sep 17 00:00:00 2001 From: qjfoidnh Date: Wed, 25 Dec 2024 02:20:25 +0800 Subject: [PATCH] fix file scan --- internal/pcsupdate/pcsupdate.go | 44 ++++++++++++++++----------------- pcsutil/file.go | 17 +++++++------ 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/internal/pcsupdate/pcsupdate.go b/internal/pcsupdate/pcsupdate.go index 6a6170a..7f18c4c 100644 --- a/internal/pcsupdate/pcsupdate.go +++ b/internal/pcsupdate/pcsupdate.go @@ -84,30 +84,28 @@ func CheckUpdate(version string, yes bool) { builder := &strings.Builder{} builder.WriteString("BaiduPCS-Go-" + releaseInfo.TagName + "-" + runtime.GOOS + "-.*?") - if runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") { - builder.WriteString("arm") - } else { - switch runtime.GOARCH { - case "amd64": - builder.WriteString("(amd64|x86_64|x64)") - case "386": - builder.WriteString("(386|x86)") - case "arm": - builder.WriteString("(armv5|armv7|arm)") - case "arm64": - builder.WriteString("arm64") - case "mips": - builder.WriteString("mips") - case "mips64": - builder.WriteString("mips64") - case "mipsle": - builder.WriteString("(mipsle|mipsel)") - case "mips64le": - builder.WriteString("(mips64le|mips64el)") - default: - builder.WriteString(runtime.GOARCH) - } + + switch runtime.GOARCH { + case "amd64": + builder.WriteString("(amd64|x86_64|x64)") + case "386": + builder.WriteString("(386|x86)") + case "arm": + builder.WriteString("(armv5|armv7|arm)") + case "arm64": + builder.WriteString("arm64") + case "mips": + builder.WriteString("mips") + case "mips64": + builder.WriteString("mips64") + case "mipsle": + builder.WriteString("(mipsle|mipsel)") + case "mips64le": + builder.WriteString("(mips64le|mips64el)") + default: + builder.WriteString(runtime.GOARCH) } + builder.WriteString("\\.zip") exp := regexp.MustCompile(builder.String()) diff --git a/pcsutil/file.go b/pcsutil/file.go index b154829..217bdc8 100644 --- a/pcsutil/file.go +++ b/pcsutil/file.go @@ -3,6 +3,7 @@ package pcsutil import ( "github.com/kardianos/osext" "github.com/qjfoidnh/BaiduPCS-Go/pcsverbose" + "io/fs" "os" "path" "path/filepath" @@ -83,17 +84,17 @@ func WalkDir(dirPth, suffix string) (files []string, err error) { files = make([]string, 0, 32) suffix = strings.ToUpper(suffix) //忽略后缀匹配的大小写 - var walkFunc filepath.WalkFunc - walkFunc = func(filename string, fi os.FileInfo, err error) error { //遍历目录 + var walkFunc fs.WalkDirFunc + walkFunc = func(filename string, fi fs.DirEntry, err error) error { //遍历目录 if err != nil { return err } - if fi.IsDir() || fi.Size() == 0 { // 忽略目录和空文件 + if fi.IsDir() { // 忽略目录和空文件 return nil } - if fi.Mode()&os.ModeSymlink != 0 { // 读取 symbol link - err = filepath.Walk(filename+string(os.PathSeparator), walkFunc) - return err + fileInfo, err := fi.Info() + if err != nil || fileInfo.Size() == 0 { + return nil } if strings.HasSuffix(strings.ToUpper(fi.Name()), suffix) { @@ -102,7 +103,7 @@ func WalkDir(dirPth, suffix string) (files []string, err error) { return nil } - err = filepath.Walk(dirPth, walkFunc) + err = filepath.WalkDir(dirPth, walkFunc) return files, err } @@ -121,4 +122,4 @@ func ChPathLegal(p string) bool { return false } return true -} \ No newline at end of file +}