From 0e651b097fe90c0778070225458d48a0596f117c Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 3 Nov 2022 19:55:48 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E5=88=A0=E9=99=A4=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E5=90=8E=E5=BA=94=E5=85=B3=E9=97=AD=E8=AF=A5=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E7=9A=84=E5=85=B3=E7=B3=BB=E5=9B=BE=E3=80=81=E5=A4=A7=E7=BA=B2?= =?UTF-8?q?=E5=92=8C=E5=8F=8D=E9=93=BE=E9=A1=B5=E7=AD=BE=20https://github.?= =?UTF-8?q?com/siyuan-note/siyuan/issues/6468?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/api/filetree.go | 7 ------- kernel/model/file.go | 10 ++++++++++ kernel/util/path.go | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/kernel/api/filetree.go b/kernel/api/filetree.go index 758bf9dd6..7fbf21c9b 100644 --- a/kernel/api/filetree.go +++ b/kernel/api/filetree.go @@ -310,13 +310,6 @@ func removeDoc(c *gin.Context) { ret.Msg = err.Error() return } - - evt := util.NewCmdResult("remove", 0, util.PushModeBroadcast, util.PushModeNone) - evt.Data = map[string]interface{}{ - "box": notebook, - "path": p, - } - util.PushEvent(evt) } func removeDocs(c *gin.Context) { diff --git a/kernel/model/file.go b/kernel/model/file.go index 6ac1fd0c4..3a990bea9 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -1227,6 +1227,8 @@ func removeDoc(box *Box, p string) (err error) { copyDocAssetsToDataAssets(box.ID, p) rootID := tree.ID + var removeIDs []string + removeIDs = append(removeIDs, rootID) dir := path.Dir(p) childrenDir := path.Join(dir, rootID) existChildren := box.Exist(childrenDir) @@ -1246,6 +1248,8 @@ func removeDoc(box *Box, p string) (err error) { if existChildren { box.Remove(childrenDir) + ids := util.GetChildDocIDs(filepath.Join(util.DataDir, tree.Box, childrenDir)) + removeIDs = append(removeIDs, ids...) } treenode.RemoveBlockTreesByPathPrefix(childrenDir) @@ -1259,6 +1263,12 @@ func removeDoc(box *Box, p string) (err error) { } cache.RemoveDocIAL(p) + + evt := util.NewCmdResult("remove", 0, util.PushModeBroadcast, util.PushModeNone) + evt.Data = map[string]interface{}{ + "ids": removeIDs, + } + util.PushEvent(evt) return } diff --git a/kernel/util/path.go b/kernel/util/path.go index 54dad6677..26ece4a0b 100644 --- a/kernel/util/path.go +++ b/kernel/util/path.go @@ -202,3 +202,22 @@ func FilterSelfChildDocs(paths []string) (ret []string) { } return } + +func GetChildDocIDs(parentDocDirAbsPath string) (ret []string) { + if !gulu.File.IsDir(parentDocDirAbsPath) { + return + } + + filepath.Walk(parentDocDirAbsPath, func(path string, info os.FileInfo, err error) error { + if info.IsDir() { + return nil + } + if !strings.HasSuffix(path, ".sy") { + return nil + } + id := path[len(parentDocDirAbsPath)+1 : len(path)-3] + ret = append(ret, id) + return nil + }) + return +}