From 326945d4b6ec761653010139d2298ce3a532502f Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 16 Feb 2023 09:29:10 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E5=AD=90=E6=96=87=E6=A1=A3=E7=BC=BA?= =?UTF-8?q?=E5=A4=B1=E7=88=B6=E6=96=87=E6=A1=A3=E6=97=B6=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=A1=A5=E5=85=A8=20https://github.com/siyuan-note/siyuan/issu?= =?UTF-8?q?es/7376?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/filesys/tree.go | 2 ++ kernel/model/index_fix.go | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/kernel/filesys/tree.go b/kernel/filesys/tree.go index 3e06492e5..64f453250 100644 --- a/kernel/filesys/tree.go +++ b/kernel/filesys/tree.go @@ -82,11 +82,13 @@ func LoadTreeByData(data []byte, boxID, p string, luteEngine *lute.Lute) (ret *p parentData, readErr := filelock.ReadFile(parentAbsPath) if nil != readErr { if os.IsNotExist(readErr) { + // 子文档缺失父文档时自动补全 https://github.com/siyuan-note/siyuan/issues/7376 parentTree := treenode.NewTree(boxID, parentPath, hPathBuilder.String()+"Untitled", "Untitled") if writeErr := WriteTree(parentTree); nil != writeErr { logging.LogErrorf("rebuild parent tree [%s] failed: %s", parentAbsPath, writeErr) } else { logging.LogInfof("rebuilt parent tree [%s]", parentAbsPath) + treenode.IndexBlockTree(parentTree) } } else { logging.LogWarnf("read parent tree data [%s] failed: %s", parentAbsPath, readErr) diff --git a/kernel/model/index_fix.go b/kernel/model/index_fix.go index e7b742738..cd4d08ca9 100644 --- a/kernel/model/index_fix.go +++ b/kernel/model/index_fix.go @@ -128,9 +128,26 @@ func resetDuplicateBlocksOnFileSys() { boxPath := filepath.Join(util.DataDir, box.ID) filepath.Walk(boxPath, func(path string, info os.FileInfo, err error) error { if info.IsDir() { + if boxPath == path { + // 跳过根路径(笔记本文件夹) + return nil + } + if strings.HasPrefix(info.Name(), ".") { 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 } @@ -234,6 +251,11 @@ func fixBlockTreeByFileSys() { boxPath := filepath.Join(util.DataDir, box.ID) var paths []string filepath.Walk(boxPath, func(path string, info os.FileInfo, err error) error { + if boxPath == path { + // 跳过根路径(笔记本文件夹) + return nil + } + if info.IsDir() { if strings.HasPrefix(info.Name(), ".") { return filepath.SkipDir