An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:recycle: Improve copy file stability https://github.com/siyuan-note/siyuan/issues/7837
Liang Dingdd5d97538186
diff --git a/kernel/model/appearance.go b/kernel/model/appearance.goindex a44f2f6eb0..b3ebac6a97 100644--- a/kernel/model/appearance.go+++ b/kernel/model/appearance.go@@ -27,6 +27,7 @@ import ("github.com/88250/gulu""github.com/fsnotify/fsnotify"+ "github.com/siyuan-note/filelock""github.com/siyuan-note/logging""github.com/siyuan-note/siyuan/kernel/bazaar""github.com/siyuan-note/siyuan/kernel/util"@@ -42,7 +43,7 @@ func InitAppearance() {unloadThemes()from := filepath.Join(util.WorkingDir, "appearance")- if err := gulu.File.Copy(from, util.AppearancePath); nil != err {+ if err := filelock.Copy(from, util.AppearancePath); nil != err {logging.LogErrorf("copy appearance resources from [%s] to [%s] failed: %s", from, util.AppearancePath, err)util.ReportFileSysFatalError(err)returndiff --git a/kernel/model/assets.go b/kernel/model/assets.goindex 23eed4f10d..5eced62d42 100644--- a/kernel/model/assets.go+++ b/kernel/model/assets.go@@ -110,7 +110,7 @@ func NetImg2LocalAssets(rootID, originalURL string) (err error) {name = "net-img-" + namename = util.AssetName(name)writePath := filepath.Join(assetsDirPath, name)- if err = gulu.File.Copy(u, writePath); nil != err {+ if err = filelock.Copy(u, writePath); nil != err {logging.LogErrorf("copy [%s] to [%s] failed: %s", u, writePath, err)return ast.WalkSkipChildren}@@ -412,7 +412,7 @@ func RemoveUnusedAssets() (ret []string) {for _, p := range unusedAssets {historyPath := filepath.Join(historyDir, p)if p = filepath.Join(util.DataDir, p); gulu.File.IsExist(p) {- if err = gulu.File.Copy(p, historyPath); nil != err {+ if err = filelock.Copy(p, historyPath); nil != err {return}@@ -455,7 +455,7 @@ func RemoveUnusedAsset(p string) (ret string) {newP := strings.TrimPrefix(absPath, util.DataDir)historyPath := filepath.Join(historyDir, newP)if gulu.File.IsExist(absPath) {- if err = gulu.File.Copy(absPath, historyPath); nil != err {+ if err = filelock.Copy(absPath, historyPath); nil != err {return}diff --git a/kernel/model/css.go b/kernel/model/css.goindex 9313dca6ff..664fdedc77 100644--- a/kernel/model/css.go+++ b/kernel/model/css.go@@ -26,6 +26,7 @@ import ("github.com/88250/css""github.com/88250/gulu"+ "github.com/siyuan-note/filelock""github.com/siyuan-note/logging""github.com/siyuan-note/siyuan/kernel/util")@@ -161,7 +162,7 @@ func ReadCustomCSS(themeName string) (ret map[string]map[string]string, err errocustom := filepath.Join(themePath, "custom.css")if !gulu.File.IsExist(custom) {- if err = gulu.File.CopyFile(theme, custom); nil != err {+ if err = filelock.Copy(theme, custom); nil != err {logging.LogErrorf("copy theme [%s] to [%s] failed: %s", theme, custom, err)return}diff --git a/kernel/model/export.go b/kernel/model/export.goindex 852850c6df..5d5e1f9b9f 100644--- a/kernel/model/export.go+++ b/kernel/model/export.go@@ -170,7 +170,7 @@ func ExportSystemLog() (zipPath string) {appLog := filepath.Join(util.HomeDir, ".config", "siyuan", "app.log")if gulu.File.IsExist(appLog) {to := filepath.Join(exportFolder, "app.log")- if err := gulu.File.CopyFile(appLog, to); nil != err {+ if err := filelock.Copy(appLog, to); nil != err {logging.LogErrorf("copy app log from [%s] to [%s] failed: %s", err, appLog, to)}}@@ -178,7 +178,7 @@ func ExportSystemLog() (zipPath string) {kernelLog := filepath.Join(util.HomeDir, ".config", "siyuan", "kernel.log")if gulu.File.IsExist(kernelLog) {to := filepath.Join(exportFolder, "kernel.log")- if err := gulu.File.CopyFile(kernelLog, to); nil != err {+ if err := filelock.Copy(kernelLog, to); nil != err {logging.LogErrorf("copy kernel log from [%s] to [%s] failed: %s", err, kernelLog, to)}}@@ -186,7 +186,7 @@ func ExportSystemLog() (zipPath string) {siyuanLog := filepath.Join(util.TempDir, "siyuan.log")if gulu.File.IsExist(siyuanLog) {to := filepath.Join(exportFolder, "siyuan.log")- if err := gulu.File.CopyFile(siyuanLog, to); nil != err {+ if err := filelock.Copy(siyuanLog, to); nil != err {logging.LogErrorf("copy kernel log from [%s] to [%s] failed: %s", err, siyuanLog, to)}}@@ -355,13 +355,13 @@ func ExportDocx(id, savePath string, removeAssets, merge bool) (err error) {return errors.New(msg)}- if err = gulu.File.Copy(tmpDocxPath, filepath.Join(savePath, name+".docx")); nil != err {+ if err = filelock.Copy(tmpDocxPath, filepath.Join(savePath, name+".docx")); nil != err {logging.LogErrorf("export docx failed: %s", err)return errors.New(fmt.Sprintf(Conf.Language(14), err))}if tmpAssets := filepath.Join(tmpDir, "assets"); !removeAssets && gulu.File.IsDir(tmpAssets) {- if err = gulu.File.Copy(tmpAssets, filepath.Join(savePath, "assets")); nil != err {+ if err = filelock.Copy(tmpAssets, filepath.Join(savePath, "assets")); nil != err {logging.LogErrorf("export docx failed: %s", err)return errors.New(fmt.Sprintf(Conf.Language(14), err))}@@ -409,7 +409,7 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom stringcontinue}targetAbsPath := filepath.Join(savePath, asset)- if err = gulu.File.Copy(srcAbsPath, targetAbsPath); nil != err {+ if err = filelock.Copy(srcAbsPath, targetAbsPath); nil != err {logging.LogWarnf("copy asset from [%s] to [%s] failed: %s", srcAbsPath, targetAbsPath, err)}}@@ -419,7 +419,7 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom stringfor _, src := range srcs {from := filepath.Join(util.WorkingDir, src)to := filepath.Join(savePath, src)- if err := gulu.File.Copy(from, to); nil != err {+ if err := filelock.Copy(from, to); nil != err {logging.LogWarnf("copy stage from [%s] to [%s] failed: %s", from, savePath, err)return}@@ -433,7 +433,7 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom stringfor _, src := range srcs {from := filepath.Join(util.AppearancePath, src)to := filepath.Join(savePath, "appearance", src)- if err := gulu.File.Copy(from, to); nil != err {+ if err := filelock.Copy(from, to); nil != err {logging.LogErrorf("copy appearance from [%s] to [%s] failed: %s", from, savePath, err)return}@@ -444,7 +444,7 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom stringfor _, emoji := range emojis {from := filepath.Join(util.DataDir, emoji)to := filepath.Join(savePath, emoji)- if err := gulu.File.Copy(from, to); nil != err {+ if err := filelock.Copy(from, to); nil != err {logging.LogErrorf("copy emojis from [%s] to [%s] failed: %s", from, savePath, err)return}@@ -546,7 +546,7 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, docontinue}targetAbsPath := filepath.Join(savePath, asset)- if err = gulu.File.Copy(srcAbsPath, targetAbsPath); nil != err {+ if err = filelock.Copy(srcAbsPath, targetAbsPath); nil != err {logging.LogWarnf("copy asset from [%s] to [%s] failed: %s", srcAbsPath, targetAbsPath, err)}}@@ -558,7 +558,7 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, dofor _, src := range srcs {from := filepath.Join(util.WorkingDir, src)to := filepath.Join(savePath, src)- if err := gulu.File.Copy(from, to); nil != err {+ if err := filelock.Copy(from, to); nil != err {logging.LogErrorf("copy stage from [%s] to [%s] failed: %s", from, savePath, err)return}@@ -572,7 +572,7 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, dofor _, src := range srcs {from := filepath.Join(util.AppearancePath, src)to := filepath.Join(savePath, "appearance", src)- if err := gulu.File.Copy(from, to); nil != err {+ if err := filelock.Copy(from, to); nil != err {logging.LogErrorf("copy appearance from [%s] to [%s] failed: %s", from, savePath, err)return}@@ -583,7 +583,7 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, dofor _, emoji := range emojis {from := filepath.Join(util.DataDir, emoji)to := filepath.Join(savePath, emoji)- if err := gulu.File.Copy(from, to); nil != err {+ if err := filelock.Copy(from, to); nil != err {logging.LogErrorf("copy emojis from [%s] to [%s] failed: %s", from, savePath, err)return}@@ -1124,11 +1124,7 @@ func exportMarkdownZip(boxID, baseFolderName string, docPaths []string) (zipPath}destPath := filepath.Join(writeFolder, asset)- if gulu.File.IsDir(srcPath) {- err = gulu.File.Copy(srcPath, destPath)- } else {- err = gulu.File.CopyFile(srcPath, destPath)- }+ err = filelock.Copy(srcPath, destPath)if nil != err {logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", srcPath, destPath, err)continue@@ -1355,11 +1351,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (}destPath := filepath.Join(exportFolder, asset)- if gulu.File.IsDir(srcPath) {- assetErr = gulu.File.Copy(srcPath, destPath)- } else {- assetErr = gulu.File.CopyFile(srcPath, destPath)- }+ assetErr = filelock.Copy(srcPath, destPath)if nil != assetErr {logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", srcPath, destPath, assetErr)continuediff --git a/kernel/model/history.go b/kernel/model/history.goindex 2b39efd4d5..520cd3e9a7 100644--- a/kernel/model/history.go+++ b/kernel/model/history.go@@ -273,7 +273,7 @@ func RollbackAssetsHistory(historyPath string) (err error) {from := historyPathto := filepath.Join(util.DataDir, "assets", filepath.Base(historyPath))- if err = gulu.File.Copy(from, to); nil != err {+ if err = filelock.Copy(from, to); nil != err {logging.LogErrorf("copy file [%s] to [%s] failed: %s", from, to, err)return}@@ -290,7 +290,7 @@ func RollbackNotebookHistory(historyPath string) (err error) {from := historyPathto := filepath.Join(util.DataDir, filepath.Base(historyPath))- if err = gulu.File.Copy(from, to); nil != err {+ if err = filelock.Copy(from, to); nil != err {logging.LogErrorf("copy file [%s] to [%s] failed: %s", from, to, err)return}