mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 08:30:12 +01:00
🎨 子文档缺失父文档时自动补全 https://github.com/siyuan-note/siyuan/issues/7376
This commit is contained in:
parent
0f6b4bd395
commit
326945d4b6
2 changed files with 24 additions and 0 deletions
|
|
@ -82,11 +82,13 @@ func LoadTreeByData(data []byte, boxID, p string, luteEngine *lute.Lute) (ret *p
|
||||||
parentData, readErr := filelock.ReadFile(parentAbsPath)
|
parentData, readErr := filelock.ReadFile(parentAbsPath)
|
||||||
if nil != readErr {
|
if nil != readErr {
|
||||||
if os.IsNotExist(readErr) {
|
if os.IsNotExist(readErr) {
|
||||||
|
// 子文档缺失父文档时自动补全 https://github.com/siyuan-note/siyuan/issues/7376
|
||||||
parentTree := treenode.NewTree(boxID, parentPath, hPathBuilder.String()+"Untitled", "Untitled")
|
parentTree := treenode.NewTree(boxID, parentPath, hPathBuilder.String()+"Untitled", "Untitled")
|
||||||
if writeErr := WriteTree(parentTree); nil != writeErr {
|
if writeErr := WriteTree(parentTree); nil != writeErr {
|
||||||
logging.LogErrorf("rebuild parent tree [%s] failed: %s", parentAbsPath, writeErr)
|
logging.LogErrorf("rebuild parent tree [%s] failed: %s", parentAbsPath, writeErr)
|
||||||
} else {
|
} else {
|
||||||
logging.LogInfof("rebuilt parent tree [%s]", parentAbsPath)
|
logging.LogInfof("rebuilt parent tree [%s]", parentAbsPath)
|
||||||
|
treenode.IndexBlockTree(parentTree)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logging.LogWarnf("read parent tree data [%s] failed: %s", parentAbsPath, readErr)
|
logging.LogWarnf("read parent tree data [%s] failed: %s", parentAbsPath, readErr)
|
||||||
|
|
|
||||||
|
|
@ -128,9 +128,26 @@ func resetDuplicateBlocksOnFileSys() {
|
||||||
boxPath := filepath.Join(util.DataDir, box.ID)
|
boxPath := filepath.Join(util.DataDir, box.ID)
|
||||||
filepath.Walk(boxPath, func(path string, info os.FileInfo, err error) error {
|
filepath.Walk(boxPath, func(path string, info os.FileInfo, err error) error {
|
||||||
if info.IsDir() {
|
if info.IsDir() {
|
||||||
|
if boxPath == path {
|
||||||
|
// 跳过根路径(笔记本文件夹)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(info.Name(), ".") {
|
if strings.HasPrefix(info.Name(), ".") {
|
||||||
return filepath.SkipDir
|
return filepath.SkipDir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !ast.IsNodeIDPattern(info.Name()) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if util.IsEmptyDir(filepath.Join(path)) {
|
||||||
|
// 删除空的子文档文件夹
|
||||||
|
if removeErr := os.RemoveAll(path); nil != removeErr {
|
||||||
|
logging.LogErrorf("remove empty folder failed: %s", removeErr)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -234,6 +251,11 @@ func fixBlockTreeByFileSys() {
|
||||||
boxPath := filepath.Join(util.DataDir, box.ID)
|
boxPath := filepath.Join(util.DataDir, box.ID)
|
||||||
var paths []string
|
var paths []string
|
||||||
filepath.Walk(boxPath, func(path string, info os.FileInfo, err error) error {
|
filepath.Walk(boxPath, func(path string, info os.FileInfo, err error) error {
|
||||||
|
if boxPath == path {
|
||||||
|
// 跳过根路径(笔记本文件夹)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if info.IsDir() {
|
if info.IsDir() {
|
||||||
if strings.HasPrefix(info.Name(), ".") {
|
if strings.HasPrefix(info.Name(), ".") {
|
||||||
return filepath.SkipDir
|
return filepath.SkipDir
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue