Skip to content

Commit

Permalink
🎨 Improve stability of data sync on some file systems siyuan-note/siy…
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Oct 28, 2023
1 parent 0822490 commit cfb485a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 11 additions & 2 deletions repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}
6 changes: 3 additions & 3 deletions sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit cfb485a

Please sign in to comment.