From b4e4a1eaff491722053bc75906d7b2bb34da9d4b Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Wed, 15 Feb 2023 09:35:46 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=A0=A1=E9=AA=8C=E7=B4=A2=E5=BC=95?= =?UTF-8?q?=E9=98=B6=E6=AE=B5=E8=87=AA=E5=8A=A8=E5=88=A0=E9=99=A4=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E9=81=97=E7=95=99=E7=9A=84=E7=AC=94=E8=AE=B0=E6=9C=AC?= =?UTF-8?q?=20history=20=E6=96=87=E4=BB=B6=E5=A4=B9=20https://github.com/s?= =?UTF-8?q?iyuan-note/siyuan/issues/7370?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/index_fix.go | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/kernel/model/index_fix.go b/kernel/model/index_fix.go index 8898ebf34..e7b742738 100644 --- a/kernel/model/index_fix.go +++ b/kernel/model/index_fix.go @@ -115,9 +115,26 @@ func resetDuplicateBlocksOnFileSys() { blockIDs := map[string]bool{} needRefreshUI := false for _, box := range boxes { + // 校验索引阶段自动删除历史遗留的笔记本 history 文件夹 + legacyHistory := filepath.Join(util.DataDir, box.ID, ".siyuan", "history") + if gulu.File.IsDir(legacyHistory) { + if removeErr := os.RemoveAll(legacyHistory); nil != removeErr { + logging.LogErrorf("remove legacy history failed: %s", removeErr) + } else { + logging.LogInfof("removed legacy history [%s]", legacyHistory) + } + } + boxPath := filepath.Join(util.DataDir, box.ID) filepath.Walk(boxPath, func(path string, info os.FileInfo, err error) error { - if info.IsDir() || filepath.Ext(path) != ".sy" || strings.Contains(filepath.ToSlash(path), "/assets/") { + if info.IsDir() { + if strings.HasPrefix(info.Name(), ".") { + return filepath.SkipDir + } + return nil + } + + if filepath.Ext(path) != ".sy" || strings.Contains(filepath.ToSlash(path), "/assets/") { return nil } @@ -217,11 +234,20 @@ 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 !info.IsDir() && filepath.Ext(path) == ".sy" && !strings.Contains(filepath.ToSlash(path), "/assets/") { - p := path[len(boxPath):] - p = filepath.ToSlash(p) - paths = append(paths, p) + if info.IsDir() { + if strings.HasPrefix(info.Name(), ".") { + return filepath.SkipDir + } + return nil } + + if filepath.Ext(path) != ".sy" || strings.Contains(filepath.ToSlash(path), "/assets/") { + return nil + } + + p := path[len(boxPath):] + p = filepath.ToSlash(p) + paths = append(paths, p) return nil })