Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Uninstalling plugins, widgets and templates may cause data sync errors https://github.com/siyuan-note/siyuan/issues/10324

Daniel745c9bcf99f9
diff --git a/kernel/bazaar/plugin.go b/kernel/bazaar/plugin.go
index 002be1dc49..3d753041b8 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 94f4f40491..f1594028aa 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 501f9669b0..6611a8c439 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 1d22369cb4..6786431d05 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 45c70eae81..9be24e3b8f 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 d2c04e1526..d610691041 100644
--- a/kernel/model/index_fix.go
+++ b/kernel/model/index_fix.go
@@ -173,9 +173,9 @@ func resetDuplicateBlocksOnFileSys() {
return nil
}
- if util.IsEmptyDir(filepath.Join(path)) {
+ if util.IsEmptyDir(path) {
// 删除空的子文档文件夹
- if removeErr := os.RemoveAll(path); nil != removeErr {
+ if removeErr := filelock.Remove(path); nil != removeErr {
logging.LogErrorf("remove empty folder failed: %s", removeErr)
}
return nil
@@ -283,7 +283,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 +411,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 1d05ab2af1..9e50ede1be 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