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

This commit is contained in:
Liang Ding 2022-11-03 20:10:42 +08:00
parent 0e651b097f
commit 43ae47a902
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
2 changed files with 13 additions and 35 deletions

View File

@ -1241,16 +1241,17 @@ func removeDoc(box *Box, p string) (err error) {
} }
indexHistoryDir(filepath.Base(historyDir), NewLute()) indexHistoryDir(filepath.Base(historyDir), NewLute())
box.removeSort(rootID, p) if existChildren {
ids := util.GetChildDocIDs(filepath.Join(util.DataDir, tree.Box, childrenDir))
removeIDs = append(removeIDs, ids...)
if err = box.Remove(childrenDir); nil != err {
return
}
}
if err = box.Remove(p); nil != err { if err = box.Remove(p); nil != err {
return return
} }
box.removeSort(removeIDs)
if existChildren {
box.Remove(childrenDir)
ids := util.GetChildDocIDs(filepath.Join(util.DataDir, tree.Box, childrenDir))
removeIDs = append(removeIDs, ids...)
}
treenode.RemoveBlockTreesByPathPrefix(childrenDir) treenode.RemoveBlockTreesByPathPrefix(childrenDir)
sql.RemoveTreePathQueue(box.ID, childrenDir) sql.RemoveTreePathQueue(box.ID, childrenDir)
@ -1659,30 +1660,7 @@ func (box *Box) fillSort(files *[]*File) {
} }
} }
func (box *Box) removeSort(rootID, path string) { func (box *Box) removeSort(ids []string) {
absRoot := filepath.Join(util.DataDir, box.ID, path)
absRootDir := strings.TrimSuffix(absRoot, ".sy")
toRemoves := map[string]bool{rootID: true}
filepath.Walk(absRootDir, func(path string, info fs.FileInfo, err error) error {
if nil == info {
return nil
}
name := info.Name()
isDir := info.IsDir()
if util.IsReservedFilename(name) {
if isDir {
return filepath.SkipDir
}
return nil
}
if !isDir && strings.HasSuffix(name, ".sy") {
id := strings.TrimSuffix(name, ".sy")
toRemoves[id] = true
}
return nil
})
confPath := filepath.Join(util.DataDir, box.ID, ".siyuan", "sort.json") confPath := filepath.Join(util.DataDir, box.ID, ".siyuan", "sort.json")
if !gulu.File.IsExist(confPath) { if !gulu.File.IsExist(confPath) {
return return
@ -1700,7 +1678,7 @@ func (box *Box) removeSort(rootID, path string) {
return return
} }
for toRemove := range toRemoves { for _, toRemove := range ids {
delete(fullSortIDs, toRemove) delete(fullSortIDs, toRemove)
} }

View File

@ -208,14 +208,14 @@ func GetChildDocIDs(parentDocDirAbsPath string) (ret []string) {
return return
} }
filepath.Walk(parentDocDirAbsPath, func(path string, info os.FileInfo, err error) error { filepath.Walk(parentDocDirAbsPath, func(p string, info os.FileInfo, err error) error {
if info.IsDir() { if info.IsDir() {
return nil return nil
} }
if !strings.HasSuffix(path, ".sy") { if !strings.HasSuffix(p, ".sy") {
return nil return nil
} }
id := path[len(parentDocDirAbsPath)+1 : len(path)-3] id := strings.TrimSuffix(filepath.Base(p), ".sy")
ret = append(ret, id) ret = append(ret, id)
return nil return nil
}) })