From cfb485a4235daa02fa38aae89a6750900a7018d3 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 28 Oct 2023 22:59:36 +0800 Subject: [PATCH] :art: Improve stability of data sync on some file systems https://github.com/siyuan-note/siyuan/issues/9541 --- repo.go | 13 +++++++++++-- sync.go | 6 +++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/repo.go b/repo.go index f5d9b9f..fcb6cef 100644 --- a/repo.go +++ b/repo.go @@ -234,11 +234,12 @@ func (repo *Repo) index(memo string, context map[string]interface{}) (ret *entit eventbus.Publish(eventbus.EvtIndexBeforeWalkData, context, repo.DataPath) err = filepath.Walk(repo.DataPath, func(path string, info os.FileInfo, err error) error { if nil != err { - logging.LogErrorf("walk data failed: %s", err) - if os.IsNotExist(err) || strings.Contains(err.Error(), "no such file or directory") { + if isNoSuchFileOrDirErr(err) { // An error `Failed to create data snapshot` is occasionally reported during automatic data sync https://github.com/siyuan-note/siyuan/issues/8998 + logging.LogInfof("ignore not exist err [%s]", err) return nil } + logging.LogErrorf("walk data failed: %s", err) return err } if ignored, ignoreResult := repo.builtInIgnore(info, path); ignored || nil != ignoreResult { @@ -670,3 +671,11 @@ func (repo *Repo) checkoutFile(file *entity.File, checkoutDir string, count, tot eventbus.Publish(eventbus.EvtCheckoutUpsertFile, context, count, total) return } + +func isNoSuchFileOrDirErr(err error) bool { + if nil == err { + return false + } + + return os.IsNotExist(err) || strings.Contains(err.Error(), "no such file or directory") +} diff --git a/sync.go b/sync.go index 42316da..8571f9a 100644 --- a/sync.go +++ b/sync.go @@ -97,7 +97,7 @@ func (repo *Repo) Sync(context map[string]interface{}) (mergeResult *MergeResult defer repo.unlockCloud(context) mergeResult, trafficStat, err = repo.sync(context) - if e, ok := err.(*os.PathError); ok && os.IsNotExist(err) { + if e, ok := err.(*os.PathError); ok && isNoSuchFileOrDirErr(err) { p := e.Path if !strings.Contains(p, "objects") { return @@ -1129,7 +1129,7 @@ func (repo *Repo) uploadChunks(upsertChunkIDs []string, context map[string]inter func (repo *Repo) localNotFoundChunks(chunkIDs []string) (ret []string, err error) { for _, chunkID := range chunkIDs { if _, getChunkErr := repo.store.Stat(chunkID); nil != getChunkErr { - if os.IsNotExist(getChunkErr) { + if isNoSuchFileOrDirErr(err) { ret = append(ret, chunkID) continue } @@ -1144,7 +1144,7 @@ func (repo *Repo) localNotFoundChunks(chunkIDs []string) (ret []string, err erro func (repo *Repo) localNotFoundFiles(fileIDs []string) (ret []string, err error) { for _, fileID := range fileIDs { if _, getFileErr := repo.store.Stat(fileID); nil != getFileErr { - if os.IsNotExist(getFileErr) { + if isNoSuchFileOrDirErr(err) { ret = append(ret, fileID) continue }