This commit is contained in:
Liang Ding 2023-03-31 10:34:30 +08:00
parent e2a3aa0ef8
commit 849476b88c
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
5 changed files with 24 additions and 30 deletions

View file

@ -27,6 +27,7 @@ import (
"github.com/88250/gulu" "github.com/88250/gulu"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/logging" "github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/bazaar" "github.com/siyuan-note/siyuan/kernel/bazaar"
"github.com/siyuan-note/siyuan/kernel/util" "github.com/siyuan-note/siyuan/kernel/util"
@ -42,7 +43,7 @@ func InitAppearance() {
unloadThemes() unloadThemes()
from := filepath.Join(util.WorkingDir, "appearance") 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) logging.LogErrorf("copy appearance resources from [%s] to [%s] failed: %s", from, util.AppearancePath, err)
util.ReportFileSysFatalError(err) util.ReportFileSysFatalError(err)
return return

View file

@ -110,7 +110,7 @@ func NetImg2LocalAssets(rootID, originalURL string) (err error) {
name = "net-img-" + name name = "net-img-" + name
name = util.AssetName(name) name = util.AssetName(name)
writePath := filepath.Join(assetsDirPath, 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) logging.LogErrorf("copy [%s] to [%s] failed: %s", u, writePath, err)
return ast.WalkSkipChildren return ast.WalkSkipChildren
} }
@ -412,7 +412,7 @@ func RemoveUnusedAssets() (ret []string) {
for _, p := range unusedAssets { for _, p := range unusedAssets {
historyPath := filepath.Join(historyDir, p) historyPath := filepath.Join(historyDir, p)
if p = filepath.Join(util.DataDir, p); gulu.File.IsExist(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 return
} }
@ -455,7 +455,7 @@ func RemoveUnusedAsset(p string) (ret string) {
newP := strings.TrimPrefix(absPath, util.DataDir) newP := strings.TrimPrefix(absPath, util.DataDir)
historyPath := filepath.Join(historyDir, newP) historyPath := filepath.Join(historyDir, newP)
if gulu.File.IsExist(absPath) { if gulu.File.IsExist(absPath) {
if err = gulu.File.Copy(absPath, historyPath); nil != err { if err = filelock.Copy(absPath, historyPath); nil != err {
return return
} }

View file

@ -26,6 +26,7 @@ import (
"github.com/88250/css" "github.com/88250/css"
"github.com/88250/gulu" "github.com/88250/gulu"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/logging" "github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/util" "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") custom := filepath.Join(themePath, "custom.css")
if !gulu.File.IsExist(custom) { 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) logging.LogErrorf("copy theme [%s] to [%s] failed: %s", theme, custom, err)
return return
} }

View file

@ -170,7 +170,7 @@ func ExportSystemLog() (zipPath string) {
appLog := filepath.Join(util.HomeDir, ".config", "siyuan", "app.log") appLog := filepath.Join(util.HomeDir, ".config", "siyuan", "app.log")
if gulu.File.IsExist(appLog) { if gulu.File.IsExist(appLog) {
to := filepath.Join(exportFolder, "app.log") 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) 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") kernelLog := filepath.Join(util.HomeDir, ".config", "siyuan", "kernel.log")
if gulu.File.IsExist(kernelLog) { if gulu.File.IsExist(kernelLog) {
to := filepath.Join(exportFolder, "kernel.log") 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) 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") siyuanLog := filepath.Join(util.TempDir, "siyuan.log")
if gulu.File.IsExist(siyuanLog) { if gulu.File.IsExist(siyuanLog) {
to := filepath.Join(exportFolder, "siyuan.log") 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) 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) 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) logging.LogErrorf("export docx failed: %s", err)
return errors.New(fmt.Sprintf(Conf.Language(14), err)) return errors.New(fmt.Sprintf(Conf.Language(14), err))
} }
if tmpAssets := filepath.Join(tmpDir, "assets"); !removeAssets && gulu.File.IsDir(tmpAssets) { 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) logging.LogErrorf("export docx failed: %s", err)
return errors.New(fmt.Sprintf(Conf.Language(14), 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 continue
} }
targetAbsPath := filepath.Join(savePath, asset) 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) 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 { for _, src := range srcs {
from := filepath.Join(util.WorkingDir, src) from := filepath.Join(util.WorkingDir, src)
to := filepath.Join(savePath, 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) logging.LogWarnf("copy stage from [%s] to [%s] failed: %s", from, savePath, err)
return return
} }
@ -433,7 +433,7 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string
for _, src := range srcs { for _, src := range srcs {
from := filepath.Join(util.AppearancePath, src) from := filepath.Join(util.AppearancePath, src)
to := filepath.Join(savePath, "appearance", 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) logging.LogErrorf("copy appearance from [%s] to [%s] failed: %s", from, savePath, err)
return return
} }
@ -444,7 +444,7 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string
for _, emoji := range emojis { for _, emoji := range emojis {
from := filepath.Join(util.DataDir, emoji) from := filepath.Join(util.DataDir, emoji)
to := filepath.Join(savePath, 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) logging.LogErrorf("copy emojis from [%s] to [%s] failed: %s", from, savePath, err)
return return
} }
@ -546,7 +546,7 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, do
continue continue
} }
targetAbsPath := filepath.Join(savePath, asset) 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) 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 { for _, src := range srcs {
from := filepath.Join(util.WorkingDir, src) from := filepath.Join(util.WorkingDir, src)
to := filepath.Join(savePath, 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) logging.LogErrorf("copy stage from [%s] to [%s] failed: %s", from, savePath, err)
return return
} }
@ -572,7 +572,7 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, do
for _, src := range srcs { for _, src := range srcs {
from := filepath.Join(util.AppearancePath, src) from := filepath.Join(util.AppearancePath, src)
to := filepath.Join(savePath, "appearance", 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) logging.LogErrorf("copy appearance from [%s] to [%s] failed: %s", from, savePath, err)
return return
} }
@ -583,7 +583,7 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, do
for _, emoji := range emojis { for _, emoji := range emojis {
from := filepath.Join(util.DataDir, emoji) from := filepath.Join(util.DataDir, emoji)
to := filepath.Join(savePath, 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) logging.LogErrorf("copy emojis from [%s] to [%s] failed: %s", from, savePath, err)
return return
} }
@ -1124,11 +1124,7 @@ func exportMarkdownZip(boxID, baseFolderName string, docPaths []string) (zipPath
} }
destPath := filepath.Join(writeFolder, asset) destPath := filepath.Join(writeFolder, asset)
if gulu.File.IsDir(srcPath) { err = filelock.Copy(srcPath, destPath)
err = gulu.File.Copy(srcPath, destPath)
} else {
err = gulu.File.CopyFile(srcPath, destPath)
}
if nil != err { if nil != err {
logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", srcPath, destPath, err) logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", srcPath, destPath, err)
continue continue
@ -1355,11 +1351,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
} }
destPath := filepath.Join(exportFolder, asset) destPath := filepath.Join(exportFolder, asset)
if gulu.File.IsDir(srcPath) { assetErr = filelock.Copy(srcPath, destPath)
assetErr = gulu.File.Copy(srcPath, destPath)
} else {
assetErr = gulu.File.CopyFile(srcPath, destPath)
}
if nil != assetErr { if nil != assetErr {
logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", srcPath, destPath, assetErr) logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", srcPath, destPath, assetErr)
continue continue

View file

@ -273,7 +273,7 @@ func RollbackAssetsHistory(historyPath string) (err error) {
from := historyPath from := historyPath
to := filepath.Join(util.DataDir, "assets", filepath.Base(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) logging.LogErrorf("copy file [%s] to [%s] failed: %s", from, to, err)
return return
} }
@ -290,7 +290,7 @@ func RollbackNotebookHistory(historyPath string) (err error) {
from := historyPath from := historyPath
to := filepath.Join(util.DataDir, filepath.Base(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) logging.LogErrorf("copy file [%s] to [%s] failed: %s", from, to, err)
return return
} }