Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2023-03-31 10:46:57 +08:00
commit e348c5ff62
7 changed files with 36 additions and 32 deletions

View file

@ -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

View file

@ -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
}

View file

@ -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
}

View file

@ -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,16 +1351,22 @@ 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
}
if !gulu.File.IsDir(srcPath) && strings.HasSuffix(strings.ToLower(srcPath), ".pdf") {
sya := srcPath + ".sya"
if gulu.File.IsExist(sya) {
// Related PDF annotation information is not exported when exporting .sy.zip https://github.com/siyuan-note/siyuan/issues/7836
if syaErr := filelock.Copy(sya, destPath+".sya"); nil != syaErr {
logging.LogErrorf("copy sya from [%s] to [%s] failed: %s", sya, destPath+".sya", syaErr)
}
}
}
copiedAssets.Add(asset)
}
}

View file

@ -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
}

View file

@ -519,7 +519,7 @@ func formatErrorMsg(err error) string {
msg = Conf.Language(24)
} else if strings.Contains(msgLowerCase, "net/http: request canceled while waiting for connection") || strings.Contains(msgLowerCase, "exceeded while awaiting") || strings.Contains(msgLowerCase, "context deadline exceeded") || strings.Contains(msgLowerCase, "timeout") || strings.Contains(msgLowerCase, "context cancellation while reading body") {
msg = Conf.Language(24)
} else if strings.Contains(msgLowerCase, "connection was") || strings.Contains(msgLowerCase, "reset by peer") || strings.Contains(msgLowerCase, "refused") || strings.Contains(msgLowerCase, "socket") {
} else if strings.Contains(msgLowerCase, "connection was") || strings.Contains(msgLowerCase, "reset by peer") || strings.Contains(msgLowerCase, "refused") || strings.Contains(msgLowerCase, "socket") || strings.Contains(msgLowerCase, "closed idle connection") || strings.Contains(msgLowerCase, "eof") {
msg = Conf.Language(28)
}
}

View file

@ -271,7 +271,7 @@ func IndexBlockTree(tree *parse.Tree) {
slice.m.Unlock()
if nil != bt {
if bt.Updated != n.IALAttr("updated") || bt.Path != tree.Path || bt.BoxID != tree.Box || bt.HPath != tree.HPath {
if bt.Updated != n.IALAttr("updated") || bt.Type != TypeAbbr(n.Type.String()) || bt.Path != tree.Path || bt.BoxID != tree.Box || bt.HPath != tree.HPath {
children := ChildBlockNodes(n) // 需要考虑子块,因为一些操作(比如移动块)后需要同时更新子块
changedNodes = append(changedNodes, children...)
}