From 8c4caf09a82a5b8adc540d92abc68194051af679 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Tue, 27 Dec 2022 21:34:07 +0100 Subject: [PATCH] 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. --- cmd/restic/cmd_repair_snapshots.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/cmd/restic/cmd_repair_snapshots.go b/cmd/restic/cmd_repair_snapshots.go index 8a51d72be..0413c43bf 100644 --- a/cmd/restic/cmd_repair_snapshots.go +++ b/cmd/restic/cmd_repair_snapshots.go @@ -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