Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2026-02-01 10:46:21 +08:00
parent 247d8e46f1
commit a4059c62bc
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 37 additions and 14 deletions

View file

@ -1523,8 +1523,10 @@ func RemoveDoc(boxID, p string) {
FlushTxQueue()
luteEngine := util.NewLute()
removeDoc(box, p, luteEngine)
tree := removeDoc(box, p, luteEngine)
IncSync()
refreshParentDocInfo(tree)
return
}
@ -1536,15 +1538,29 @@ func RemoveDocs(paths []string) {
pathsBoxes := getBoxesByPaths(paths)
FlushTxQueue()
luteEngine := util.NewLute()
var trees []*parse.Tree
for p, box := range pathsBoxes {
removeDoc(box, p, luteEngine)
tree := removeDoc(box, p, luteEngine)
trees = append(trees, tree)
}
parentTrees := map[string]*parse.Tree{}
for _, tree := range trees {
parentTree := loadParentTree(tree)
if nil != parentTree {
parentTrees[parentTree.ID] = parentTree
}
}
for _, parentTree := range parentTrees {
refreshDocInfo(parentTree)
}
return
}
func removeDoc(box *Box, p string, luteEngine *lute.Lute) {
tree, _ := filesys.LoadTree(box.ID, p, luteEngine)
if nil == tree {
func removeDoc(box *Box, p string, luteEngine *lute.Lute) (ret *parse.Tree) {
ret, _ = filesys.LoadTree(box.ID, p, luteEngine)
if nil == ret {
return
}
@ -1561,16 +1577,16 @@ func removeDoc(box *Box, p string, luteEngine *lute.Lute) {
return
}
generateAvHistoryInTree(tree, historyDir)
generateAvHistoryInTree(ret, historyDir)
copyDocAssetsToDataAssets(box.ID, p)
removeIDs := treenode.RootChildIDs(tree.ID)
removeIDs := treenode.RootChildIDs(ret.ID)
dir := path.Dir(p)
childrenDir := path.Join(dir, tree.ID)
childrenDir := path.Join(dir, ret.ID)
existChildren := box.Exist(childrenDir)
if existChildren {
absChildrenDir := filepath.Join(util.DataDir, tree.Box, childrenDir)
historyPath = filepath.Join(historyDir, tree.Box, childrenDir)
absChildrenDir := filepath.Join(util.DataDir, ret.Box, childrenDir)
historyPath = filepath.Join(historyDir, ret.Box, childrenDir)
if err = filelock.Copy(absChildrenDir, historyPath); err != nil {
logging.LogErrorf("backup [path=%s] to history [%s] failed: %s", absChildrenDir, historyPath, err)
return
@ -1578,7 +1594,7 @@ func removeDoc(box *Box, p string, luteEngine *lute.Lute) {
}
indexHistoryDir(filepath.Base(historyDir), util.NewLute())
allRemoveRootIDs := []string{tree.ID}
allRemoveRootIDs := []string{ret.ID}
allRemoveRootIDs = append(allRemoveRootIDs, removeIDs...)
allRemoveRootIDs = gulu.Str.RemoveDuplicatedElem(allRemoveRootIDs)
for _, rootID := range allRemoveRootIDs {
@ -1616,9 +1632,8 @@ func removeDoc(box *Box, p string, luteEngine *lute.Lute) {
"ids": removeIDs,
}
util.PushEvent(evt)
refreshParentDocInfo(tree)
task.AppendTask(task.DatabaseIndex, removeDoc0, tree, childrenDir)
task.AppendTask(task.DatabaseIndex, removeDoc0, ret, childrenDir)
return
}
func removeDoc0(tree *parse.Tree, childrenDir string) {

View file

@ -145,6 +145,10 @@ func refreshDocInfoWithSize(tree *parse.Tree, size uint64) {
}
func refreshParentDocInfo(tree *parse.Tree) {
if nil == tree {
return
}
parentTree := loadParentTree(tree)
if nil == parentTree {
return

View file

@ -298,6 +298,10 @@ func indexTreeInFilesystem(blockID string) error {
}
func loadParentTree(tree *parse.Tree) (ret *parse.Tree) {
if nil == tree {
return
}
boxDir := filepath.Join(util.DataDir, tree.Box)
parentDir := path.Dir(tree.Path)
if parentDir == boxDir || parentDir == "/" {