Skip to content

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

:art: Generate file history when removing av entries https://github.com/siyuan-note/siyuan/issues/13717

Danieldad22713df24
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 28015ed627..93f7fcbb68 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
}