Skip to content

Commit

Permalink
⚡ Improve walk dir performance siyuan-note/siyuan#13216
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Nov 21, 2024
1 parent 49b4b0f commit 1cf0626
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

var AndroidServerPort = 6906 // Android HTTP 服务器端口

func Walk(root string, fn filepath.WalkFunc) error {
func Walk(root string, fn fs.WalkDirFunc) error {
if strings.Contains(runtime.GOOS, "android") {
// Android 系统上统一使用 Android HTTP 服务器来遍历文件
// Data sync may cause data loss on Android 14 https://github.com/siyuan-note/siyuan/issues/10205
Expand All @@ -42,11 +42,11 @@ func Walk(root string, fn filepath.WalkFunc) error {
logging.LogInfof("walk dir [%s] cost [%s]", root, time.Since(start))
if nil != err {
logging.LogErrorf("walk dir [%s] failed: %s", root, err)
return filepath.Walk(root, fn)
return filepath.WalkDir(root, fn)
}
if 200 != resp.StatusCode {
logging.LogErrorf("walk dir [%s] failed: %d", root, resp.StatusCode)
return filepath.Walk(root, fn)
return filepath.WalkDir(root, fn)
}

result := map[string]interface{}{}
Expand Down Expand Up @@ -88,7 +88,7 @@ func Walk(root string, fn filepath.WalkFunc) error {
continue
}

err = fn(p, info, nil)
err = fn(p, fs.FileInfoToDirEntry(info), nil)
if nil != err {
if errors.Is(err, fs.SkipDir) || errors.Is(err, fs.SkipAll) {
skipFiles[p] = true
Expand All @@ -102,7 +102,7 @@ func Walk(root string, fn filepath.WalkFunc) error {
}
return nil
}
return filepath.Walk(root, fn)
return filepath.WalkDir(root, fn)
}

type RemoteFile struct {
Expand Down

0 comments on commit 1cf0626

Please sign in to comment.