diff --git a/kernel/bazaar/plugin.go b/kernel/bazaar/plugin.go index 002be1dc4..3d753041b 100644 --- a/kernel/bazaar/plugin.go +++ b/kernel/bazaar/plugin.go @@ -27,6 +27,7 @@ import ( "github.com/dustin/go-humanize" ants "github.com/panjf2000/ants/v2" + "github.com/siyuan-note/filelock" "github.com/siyuan-note/httpclient" "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/util" @@ -214,7 +215,7 @@ func InstallPlugin(repoURL, repoHash, installPath string, systemID string) error } func UninstallPlugin(installPath string) error { - if err := os.RemoveAll(installPath); nil != err { + if err := filelock.Remove(installPath); nil != err { logging.LogErrorf("remove plugin [%s] failed: %s", installPath, err) return errors.New("remove community plugin failed") } diff --git a/kernel/bazaar/template.go b/kernel/bazaar/template.go index 94f4f4049..f1594028a 100644 --- a/kernel/bazaar/template.go +++ b/kernel/bazaar/template.go @@ -27,6 +27,7 @@ import ( "github.com/dustin/go-humanize" "github.com/panjf2000/ants/v2" + "github.com/siyuan-note/filelock" "github.com/siyuan-note/httpclient" "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/util" @@ -176,7 +177,7 @@ func InstallTemplate(repoURL, repoHash, installPath string, systemID string) err } func UninstallTemplate(installPath string) error { - if err := os.RemoveAll(installPath); nil != err { + if err := filelock.Remove(installPath); nil != err { logging.LogErrorf("remove template [%s] failed: %s", installPath, err) return errors.New("remove community template failed") } diff --git a/kernel/bazaar/widget.go b/kernel/bazaar/widget.go index 501f9669b..6611a8c43 100644 --- a/kernel/bazaar/widget.go +++ b/kernel/bazaar/widget.go @@ -26,6 +26,7 @@ import ( "github.com/dustin/go-humanize" ants "github.com/panjf2000/ants/v2" + "github.com/siyuan-note/filelock" "github.com/siyuan-note/httpclient" "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/util" @@ -174,7 +175,7 @@ func InstallWidget(repoURL, repoHash, installPath string, systemID string) error } func UninstallWidget(installPath string) error { - if err := os.RemoveAll(installPath); nil != err { + if err := filelock.Remove(installPath); nil != err { logging.LogErrorf("remove widget [%s] failed: %s", installPath, err) return errors.New("remove community widget failed") } diff --git a/kernel/model/assets.go b/kernel/model/assets.go index 1d22369cb..6786431d0 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -671,7 +671,7 @@ func RemoveUnusedAssets() (ret []string) { for _, unusedAsset := range unusedAssets { if unusedAsset = filepath.Join(util.DataDir, unusedAsset); filelock.IsExist(unusedAsset) { - if err := os.RemoveAll(unusedAsset); nil != err { + if err := filelock.Remove(unusedAsset); nil != err { logging.LogErrorf("remove unused asset [%s] failed: %s", unusedAsset, err) } } @@ -709,7 +709,7 @@ func RemoveUnusedAsset(p string) (ret string) { sql.BatchRemoveAssetsQueue([]string{hash}) } - if err = os.RemoveAll(absPath); nil != err { + if err = filelock.Remove(absPath); nil != err { logging.LogErrorf("remove unused asset [%s] failed: %s", absPath, err) } ret = absPath diff --git a/kernel/model/box.go b/kernel/model/box.go index 45c70eae8..9be24e3b8 100644 --- a/kernel/model/box.go +++ b/kernel/model/box.go @@ -120,7 +120,7 @@ func ListNotebooks() (ret []*Box, err error) { } if readErr = gulu.JSON.UnmarshalJSON(data, boxConf); nil != readErr { logging.LogErrorf("parse box conf [%s] failed: %s", boxConfPath, readErr) - os.RemoveAll(boxConfPath) + filelock.Remove(boxConfPath) continue } } diff --git a/kernel/model/index_fix.go b/kernel/model/index_fix.go index d2c04e152..db58ccbe1 100644 --- a/kernel/model/index_fix.go +++ b/kernel/model/index_fix.go @@ -161,7 +161,7 @@ func resetDuplicateBlocksOnFileSys() { if info.IsDir() { if boxPath == path { - // 跳过根路径(笔记本文件夹) + // 跳过笔记本文件夹 return nil } @@ -172,14 +172,6 @@ func resetDuplicateBlocksOnFileSys() { if !ast.IsNodeIDPattern(info.Name()) { return nil } - - if util.IsEmptyDir(filepath.Join(path)) { - // 删除空的子文档文件夹 - if removeErr := os.RemoveAll(path); nil != removeErr { - logging.LogErrorf("remove empty folder failed: %s", removeErr) - } - return nil - } return nil } @@ -283,7 +275,7 @@ func recreateTree(tree *parse.Tree, absPath string) { } } - if err := os.RemoveAll(absPath); nil != err { + if err := filelock.Remove(absPath); nil != err { logging.LogWarnf("remove [%s] failed: %s", absPath, err) return } @@ -411,7 +403,7 @@ func reindexTreeByUpdated(rootUpdatedMap, dbRootUpdatedMap map[string]string) { } var rootIDs []string - for rootID, _ := range dbRootUpdatedMap { + for rootID := range dbRootUpdatedMap { if _, ok := rootUpdatedMap[rootID]; !ok { rootIDs = append(rootIDs, rootID) } diff --git a/kernel/model/ocr.go b/kernel/model/ocr.go index 1d05ab2af..9e50ede1b 100644 --- a/kernel/model/ocr.go +++ b/kernel/model/ocr.go @@ -1,7 +1,6 @@ package model import ( - "os" "path/filepath" "runtime/debug" "strings" @@ -128,7 +127,7 @@ func LoadAssetsTexts() { util.AssetsTextsLock.Lock() if err = gulu.JSON.UnmarshalJSON(data, &util.AssetsTexts); nil != err { logging.LogErrorf("unmarshal assets texts failed: %s", err) - if err = os.RemoveAll(assetsTextsPath); nil != err { + if err = filelock.Remove(assetsTextsPath); nil != err { logging.LogErrorf("removed corrupted assets texts failed: %s", err) } return