mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 16:10:12 +01:00
♻️ Improve copy file stability https://github.com/siyuan-note/siyuan/issues/7837
This commit is contained in:
parent
e2a3aa0ef8
commit
849476b88c
5 changed files with 24 additions and 30 deletions
|
|
@ -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)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ func NetImg2LocalAssets(rootID, originalURL string) (err error) {
|
|||
name = "net-img-" + name
|
||||
name = 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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 erro
|
|||
custom := 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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 string
|
|||
continue
|
||||
}
|
||||
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 string
|
|||
for _, 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 string
|
|||
for _, 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 string
|
|||
for _, 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, do
|
|||
continue
|
||||
}
|
||||
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, do
|
|||
for _, 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, do
|
|||
for _, 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, do
|
|||
for _, 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)
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -273,7 +273,7 @@ func RollbackAssetsHistory(historyPath string) (err error) {
|
|||
from := historyPath
|
||||
to := 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 := historyPath
|
||||
to := 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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue