Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: 删除父文档时子文档排序配置未清理干净 Fix https://github.com/siyuan-note/siyuan/issues/6469

Liang Ding21e354836e60
diff --git a/kernel/model/file.go b/kernel/model/file.go
index 67c775cf9c..1dd3ea0a49 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 85d79fa0cf..dbf2a17023 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
+}