diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 28015ed62..93f7fcbb6 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -2120,6 +2120,37 @@ func removeAttributeViewBlock(srcIDs []string, avID string, tx *Transaction) (er } err = av.SaveAttributeView(attrView) + + historyDir, err := GetHistoryDir(HistoryOpUpdate) + if err != nil { + logging.LogErrorf("get history dir failed: %s", err) + return + } + blockIDs := treenode.GetMirrorAttrViewBlockIDs(avID) + for _, blockID := range blockIDs { + tree := trees[blockID] + if nil == tree { + tree, _ = LoadTreeByBlockID(blockID) + } + if nil == tree { + continue + } + + historyPath := filepath.Join(historyDir, tree.Box, tree.Path) + absPath := filepath.Join(util.DataDir, tree.Box, tree.Path) + if err = filelock.Copy(absPath, historyPath); err != nil { + logging.LogErrorf("backup [path=%s] to history [%s] failed: %s", absPath, historyPath, err) + return + } + } + + srcAvPath := filepath.Join(util.DataDir, "storage", "av", avID+".json") + destAvPath := filepath.Join(historyDir, "storage", "av", avID+".json") + if copyErr := filelock.Copy(srcAvPath, destAvPath); nil != copyErr { + logging.LogErrorf("copy av [%s] failed: %s", srcAvPath, copyErr) + } + + indexHistoryDir(filepath.Base(historyDir), util.NewLute()) return }