mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-29 19:56:10 +01:00
♻️ 日志组件单独抽取项目 https://github.com/siyuan-note/siyuan/issues/5439
This commit is contained in:
parent
c8ea858976
commit
505b973c2d
70 changed files with 671 additions and 942 deletions
|
|
@ -39,6 +39,7 @@ import (
|
|||
"github.com/88250/lute/parse"
|
||||
"github.com/88250/protyle"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/filesys"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
|
|
@ -76,7 +77,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
return
|
||||
}
|
||||
if 1 != len(unzipRootPaths) {
|
||||
util.LogErrorf("invalid .sy.zip")
|
||||
logging.LogErrorf("invalid .sy.zip")
|
||||
return errors.New("invalid .sy.zip")
|
||||
}
|
||||
unzipRootPath := unzipRootPaths[0]
|
||||
|
|
@ -88,13 +89,13 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
for _, syPath := range syPaths {
|
||||
data, readErr := os.ReadFile(syPath)
|
||||
if nil != readErr {
|
||||
util.LogErrorf("read .sy [%s] failed: %s", syPath, readErr)
|
||||
logging.LogErrorf("read .sy [%s] failed: %s", syPath, readErr)
|
||||
err = readErr
|
||||
return
|
||||
}
|
||||
tree, _, parseErr := protyle.ParseJSON(luteEngine, data)
|
||||
if nil != parseErr {
|
||||
util.LogErrorf("parse .sy [%s] failed: %s", syPath, parseErr)
|
||||
logging.LogErrorf("parse .sy [%s] failed: %s", syPath, parseErr)
|
||||
err = parseErr
|
||||
return
|
||||
}
|
||||
|
|
@ -127,7 +128,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
if "" != newDefID {
|
||||
n.Tokens = gulu.Str.ToBytes(newDefID)
|
||||
} else {
|
||||
util.LogWarnf("not found def [" + n.TokensStr() + "]")
|
||||
logging.LogWarnf("not found def [" + n.TokensStr() + "]")
|
||||
}
|
||||
} else if ast.NodeBlockQueryEmbedScript == n.Type {
|
||||
for oldID, newID := range blockIDs {
|
||||
|
|
@ -153,12 +154,12 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
data = buf.Bytes()
|
||||
|
||||
if err = os.WriteFile(syPath, data, 0644); nil != err {
|
||||
util.LogErrorf("write .sy [%s] failed: %s", syPath, err)
|
||||
logging.LogErrorf("write .sy [%s] failed: %s", syPath, err)
|
||||
return
|
||||
}
|
||||
newSyPath := filepath.Join(filepath.Dir(syPath), tree.ID+".sy")
|
||||
if err = os.Rename(syPath, newSyPath); nil != err {
|
||||
util.LogErrorf("rename .sy from [%s] to [%s] failed: %s", syPath, newSyPath, err)
|
||||
logging.LogErrorf("rename .sy from [%s] to [%s] failed: %s", syPath, newSyPath, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -210,7 +211,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
for i, oldPath := range oldPaths {
|
||||
newPath := renamePaths[oldPath]
|
||||
if err = os.Rename(oldPath, newPath); nil != err {
|
||||
util.LogErrorf("rename path from [%s] to [%s] failed: %s", oldPath, renamePaths[oldPath], err)
|
||||
logging.LogErrorf("rename path from [%s] to [%s] failed: %s", oldPath, renamePaths[oldPath], err)
|
||||
return errors.New("rename path failed")
|
||||
}
|
||||
|
||||
|
|
@ -249,7 +250,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
if gulu.File.IsDir(assets) {
|
||||
dataAssets := filepath.Join(util.DataDir, "assets")
|
||||
if err = gulu.File.Copy(assets, dataAssets); nil != err {
|
||||
util.LogErrorf("copy assets from [%s] to [%s] failed: %s", assets, dataAssets, err)
|
||||
logging.LogErrorf("copy assets from [%s] to [%s] failed: %s", assets, dataAssets, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -267,7 +268,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
} else {
|
||||
block := treenode.GetBlockTreeRootByPath(boxID, toPath)
|
||||
if nil == block {
|
||||
util.LogErrorf("not found block by path [%s]", toPath)
|
||||
logging.LogErrorf("not found block by path [%s]", toPath)
|
||||
return nil
|
||||
}
|
||||
baseTargetPath = strings.TrimSuffix(block.Path, ".sy")
|
||||
|
|
@ -279,7 +280,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
}
|
||||
|
||||
if err = stableCopy(unzipRootPath, targetDir); nil != err {
|
||||
util.LogErrorf("copy data dir from [%s] to [%s] failed: %s", unzipRootPath, util.DataDir, err)
|
||||
logging.LogErrorf("copy data dir from [%s] to [%s] failed: %s", unzipRootPath, util.DataDir, err)
|
||||
err = errors.New("copy data failed")
|
||||
return
|
||||
}
|
||||
|
|
@ -305,7 +306,7 @@ func ImportData(zipPath string) (err error) {
|
|||
|
||||
files, err := filepath.Glob(filepath.Join(unzipPath, "*/*.sy"))
|
||||
if nil != err {
|
||||
util.LogErrorf("check data.zip failed: %s", err)
|
||||
logging.LogErrorf("check data.zip failed: %s", err)
|
||||
return errors.New("check data.zip failed")
|
||||
}
|
||||
if 0 < len(files) {
|
||||
|
|
@ -313,7 +314,7 @@ func ImportData(zipPath string) (err error) {
|
|||
}
|
||||
dirs, err := os.ReadDir(unzipPath)
|
||||
if nil != err {
|
||||
util.LogErrorf("check data.zip failed: %s", err)
|
||||
logging.LogErrorf("check data.zip failed: %s", err)
|
||||
return errors.New("check data.zip failed")
|
||||
}
|
||||
if 1 != len(dirs) {
|
||||
|
|
@ -326,7 +327,7 @@ func ImportData(zipPath string) (err error) {
|
|||
filelock.ReleaseAllFileLocks()
|
||||
tmpDataPath := filepath.Join(unzipPath, dirs[0].Name())
|
||||
if err = stableCopy(tmpDataPath, util.DataDir); nil != err {
|
||||
util.LogErrorf("copy data dir from [%s] to [%s] failed: %s", tmpDataPath, util.DataDir, err)
|
||||
logging.LogErrorf("copy data dir from [%s] to [%s] failed: %s", tmpDataPath, util.DataDir, err)
|
||||
err = errors.New("copy data failed")
|
||||
return
|
||||
}
|
||||
|
|
@ -350,7 +351,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||
} else {
|
||||
block := treenode.GetBlockTreeRootByPath(boxID, toPath)
|
||||
if nil == block {
|
||||
util.LogErrorf("not found block by path [%s]", toPath)
|
||||
logging.LogErrorf("not found block by path [%s]", toPath)
|
||||
return nil
|
||||
}
|
||||
baseHPath = block.HPath
|
||||
|
|
@ -436,7 +437,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||
|
||||
tree = parseKTree(data)
|
||||
if nil == tree {
|
||||
util.LogErrorf("parse tree [%s] failed", currentPath)
|
||||
logging.LogErrorf("parse tree [%s] failed", currentPath)
|
||||
return nil
|
||||
}
|
||||
tree.ID = id
|
||||
|
|
@ -476,7 +477,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||
name = util.AssetName(name)
|
||||
assetTargetPath := filepath.Join(assetDirPath, name)
|
||||
if err = gulu.File.Copy(fullPath, assetTargetPath); nil != err {
|
||||
util.LogErrorf("copy asset from [%s] to [%s] failed: %s", fullPath, assetTargetPath, err)
|
||||
logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", fullPath, assetTargetPath, err)
|
||||
return ast.WalkContinue
|
||||
}
|
||||
assetsDone[absDest] = name
|
||||
|
|
@ -524,7 +525,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||
tree := parseKTree(data)
|
||||
if nil == tree {
|
||||
msg := fmt.Sprintf("parse tree [%s] failed", localPath)
|
||||
util.LogErrorf(msg)
|
||||
logging.LogErrorf(msg)
|
||||
return errors.New(msg)
|
||||
}
|
||||
tree.ID = id
|
||||
|
|
@ -563,7 +564,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||
name = util.AssetName(name)
|
||||
assetTargetPath := filepath.Join(assetDirPath, name)
|
||||
if err = gulu.File.CopyFile(absolutePath, assetTargetPath); nil != err {
|
||||
util.LogErrorf("copy asset from [%s] to [%s] failed: %s", absolutePath, assetTargetPath, err)
|
||||
logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", absolutePath, assetTargetPath, err)
|
||||
return ast.WalkContinue
|
||||
}
|
||||
n.Tokens = gulu.Str.ToBytes("assets/" + name)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue