mirror of
https://github.com/restic/restic.git
synced 2025-01-03 05:35:43 +00:00
walker: Simplify change detection in FilterTree
Now the rewritten tree is always serialized which makes sure that we don't accidentally miss any relevant changes.
This commit is contained in:
parent
8c4caf09a8
commit
1a9705fc95
1 changed files with 9 additions and 16 deletions
|
@ -42,7 +42,6 @@ func FilterTree(ctx context.Context, repo BlobLoadSaver, nodepath string, nodeID
|
||||||
|
|
||||||
debug.Log("filterTree: %s, nodeId: %s\n", nodepath, nodeID.Str())
|
debug.Log("filterTree: %s, nodeId: %s\n", nodepath, nodeID.Str())
|
||||||
|
|
||||||
changed := false
|
|
||||||
tb := restic.NewTreeJSONBuilder()
|
tb := restic.NewTreeJSONBuilder()
|
||||||
for _, node := range curTree.Nodes {
|
for _, node := range curTree.Nodes {
|
||||||
path := path.Join(nodepath, node.Name)
|
path := path.Join(nodepath, node.Name)
|
||||||
|
@ -50,7 +49,6 @@ func FilterTree(ctx context.Context, repo BlobLoadSaver, nodepath string, nodeID
|
||||||
if visitor.PrintExclude != nil {
|
if visitor.PrintExclude != nil {
|
||||||
visitor.PrintExclude(path)
|
visitor.PrintExclude(path)
|
||||||
}
|
}
|
||||||
changed = true
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,9 +63,6 @@ func FilterTree(ctx context.Context, repo BlobLoadSaver, nodepath string, nodeID
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return restic.ID{}, err
|
return restic.ID{}, err
|
||||||
}
|
}
|
||||||
if !node.Subtree.Equal(newID) {
|
|
||||||
changed = true
|
|
||||||
}
|
|
||||||
node.Subtree = &newID
|
node.Subtree = &newID
|
||||||
err = tb.AddNode(node)
|
err = tb.AddNode(node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -75,17 +70,15 @@ func FilterTree(ctx context.Context, repo BlobLoadSaver, nodepath string, nodeID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if changed {
|
tree, err := tb.Finalize()
|
||||||
tree, err := tb.Finalize()
|
if err != nil {
|
||||||
if err != nil {
|
return restic.ID{}, err
|
||||||
return restic.ID{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save new tree
|
|
||||||
newTreeID, _, _, err := repo.SaveBlob(ctx, restic.TreeBlob, tree, restic.ID{}, false)
|
|
||||||
debug.Log("filterTree: save new tree for %s as %v\n", nodepath, newTreeID)
|
|
||||||
return newTreeID, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nodeID, nil
|
// Save new tree
|
||||||
|
newTreeID, _, _, err := repo.SaveBlob(ctx, restic.TreeBlob, tree, restic.ID{}, false)
|
||||||
|
if !newTreeID.Equal(nodeID) {
|
||||||
|
debug.Log("filterTree: save new tree for %s as %v\n", nodepath, newTreeID)
|
||||||
|
}
|
||||||
|
return newTreeID, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue