This commit is contained in:
Liang Ding 2023-01-09 17:30:19 +08:00
parent 07a5e7501a
commit 5a09669d3a
No known key found for this signature in database
GPG key ID: 136F30F901A2231D

View file

@ -1238,6 +1238,29 @@ func autoFixIndex() {
autoFixLock.Lock()
defer autoFixLock.Unlock()
// 根据文件系统补全块树
boxes := Conf.GetOpenedBoxes()
for _, box := range boxes {
boxPath := filepath.Join(util.DataDir, box.ID)
var paths []string
filepath.Walk(boxPath, func(path string, info os.FileInfo, err error) error {
if !info.IsDir() && filepath.Ext(path) == ".sy" {
p := path[len(boxPath):]
p = filepath.ToSlash(p)
paths = append(paths, p)
}
return nil
})
size := len(paths)
for i, p := range paths {
if nil == treenode.GetBlockTreeRootByPath(box.ID, p) {
reindexTreeByPath(box.ID, p, i, size)
}
}
}
// 对比块树和数据库并订正数据库
rootUpdatedMap := treenode.GetRootUpdated()
dbRootUpdatedMap, err := sql.GetRootUpdated()
if nil == err {
@ -1273,6 +1296,7 @@ func autoFixIndex() {
}
}
// 去除重复的数据库块记录
duplicatedRootIDs := sql.GetDuplicatedRootIDs()
size := len(duplicatedRootIDs)
for i, rootID := range duplicatedRootIDs {
@ -1287,6 +1311,15 @@ func autoFixIndex() {
}
}
func reindexTreeByPath(box, p string, i, size int) {
tree, err := LoadTree(box, p)
if nil != err {
return
}
reindexTree0(tree, i, size)
}
func reindexTree(rootID string, i, size int) {
root := treenode.GetBlockTree(rootID)
if nil == root {
@ -1303,6 +1336,10 @@ func reindexTree(rootID string, i, size int) {
return
}
reindexTree0(tree, i, size)
}
func reindexTree0(tree *parse.Tree, i, size int) {
updated := tree.Root.IALAttr("updated")
if "" == updated {
updated = util.TimeFromID(tree.Root.ID)