From 21e354836e60f4824d4f27ed6bfb2b267017833b Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 3 Nov 2022 20:25:56 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E5=88=A0=E9=99=A4=E7=88=B6=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E6=97=B6=E5=AD=90=E6=96=87=E6=A1=A3=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=9C=AA=E6=B8=85=E7=90=86=E5=B9=B2=E5=87=80?= =?UTF-8?q?=20Fix=20https://github.com/siyuan-note/siyuan/issues/6469?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/file.go | 28 ++-------------------------- kernel/treenode/tree.go | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/kernel/model/file.go b/kernel/model/file.go index 67c775cf9..1dd3ea0a4 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -19,7 +19,6 @@ package model import ( "errors" "fmt" - "io/fs" "math" "os" "path" @@ -1227,7 +1226,7 @@ func removeDoc(box *Box, p string) (err error) { copyDocAssetsToDataAssets(box.ID, p) var removeIDs []string - ids := rootChildIDs(tree.ID) + ids := treenode.RootChildIDs(tree.ID) removeIDs = append(removeIDs, ids...) dir := path.Dir(p) @@ -1487,7 +1486,7 @@ func moveSorts(rootID, fromBox, toBox string) { } fromRootSorts := map[string]int{} - ids := rootChildIDs(rootID) + ids := treenode.RootChildIDs(rootID) fromConfPath := filepath.Join(util.DataDir, fromBox, ".siyuan", "sort.json") fromFullSortIDs := map[string]int{} if gulu.File.IsExist(fromConfPath) { @@ -1535,29 +1534,6 @@ func moveSorts(rootID, fromBox, toBox string) { } } -func rootChildIDs(rootID string) (ret []string) { - root := treenode.GetBlockTree(rootID) - if nil == root { - return - } - - ret = append(ret, rootID) - boxLocalPath := filepath.Join(util.DataDir, root.BoxID) - subFolder := filepath.Join(boxLocalPath, strings.TrimSuffix(root.Path, ".sy")) - if !gulu.File.IsDir(subFolder) { - return - } - filepath.Walk(subFolder, func(path string, info fs.FileInfo, err error) error { - if strings.HasSuffix(path, ".sy") { - name := filepath.Base(path) - id := strings.TrimSuffix(name, ".sy") - ret = append(ret, id) - } - return nil - }) - return -} - func ChangeFileTreeSort(boxID string, paths []string) { if 1 > len(paths) { return diff --git a/kernel/treenode/tree.go b/kernel/treenode/tree.go index 85d79fa0c..dbf2a1702 100644 --- a/kernel/treenode/tree.go +++ b/kernel/treenode/tree.go @@ -19,7 +19,9 @@ package treenode import ( "crypto/sha256" "fmt" + "io/fs" "path" + "path/filepath" "sort" "strings" @@ -108,3 +110,26 @@ func IALStr(n *ast.Node) string { } return string(parse.IAL2Tokens(n.KramdownIAL)) } + +func RootChildIDs(rootID string) (ret []string) { + root := GetBlockTree(rootID) + if nil == root { + return + } + + ret = append(ret, rootID) + boxLocalPath := filepath.Join(util.DataDir, root.BoxID) + subFolder := filepath.Join(boxLocalPath, strings.TrimSuffix(root.Path, ".sy")) + if !gulu.File.IsDir(subFolder) { + return + } + filepath.Walk(subFolder, func(path string, info fs.FileInfo, err error) error { + if strings.HasSuffix(path, ".sy") { + name := filepath.Base(path) + id := strings.TrimSuffix(name, ".sy") + ret = append(ret, id) + } + return nil + }) + return +}