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

This commit is contained in:
Daniel 2025-01-04 22:07:27 +08:00
parent 9532edcab0
commit dad22713df
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -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
}