repair snapshots: Do not rename repaired files

The files in a tree must be sorted in lexical order. However, this
cannot be guaranteed when appending a filename suffix. For two files

file, file.rep

where "file" is broken, this would result in

file.repaired, file.rep

which is no longer sorted.

In addition, adding a filename suffix is also prone to filename
collisions which would require a rather complex search for a
collision-free name in order to work reliably.
This commit is contained in:
Michael Eischer 2022-12-27 21:34:07 +01:00
parent 375189488c
commit 8c4caf09a8

View file

@ -240,9 +240,7 @@ func repairTree(ctx context.Context, opts RepairOptions, repo restic.Repository,
Printf("removed defective file '%v'\n", path+node.Name)
continue
}
Printf("repaired defective file '%v'", path+node.Name)
node.Name = node.Name + ".repaired"
Printf(" to '%v'\n", node.Name)
Printf("repaired defective file '%v'\n", path+node.Name)
node.Content = newContent
node.Size = newSize
}
@ -255,9 +253,7 @@ func repairTree(ctx context.Context, opts RepairOptions, repo restic.Repository,
case lErr:
// If we get an error, we remove this subtree
changed = true
Printf("removed defective dir '%v'", path+node.Name)
node.Name = node.Name + ".repaired"
Printf("(now empty '%v')\n", node.Name)
Printf("replaced defective dir '%v'", path+node.Name)
empty, err := emptyTree(ctx, repo, opts.DryRun)
if err != nil {
return newID, true, false, err