Skip to content

Commit

Permalink
fix file scan
Browse files Browse the repository at this point in the history
  • Loading branch information
qjfoidnh committed Dec 24, 2024
1 parent a1d6648 commit b179380
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
44 changes: 21 additions & 23 deletions internal/pcsupdate/pcsupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
17 changes: 9 additions & 8 deletions pcsutil/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pcsutil
import (
"github.com/kardianos/osext"
"github.com/qjfoidnh/BaiduPCS-Go/pcsverbose"
"io/fs"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -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) {
Expand All @@ -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
}

Expand All @@ -121,4 +122,4 @@ func ChPathLegal(p string) bool {
return false
}
return true
}
}

0 comments on commit b179380

Please sign in to comment.