1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-26 01:37:12 +00:00

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