From f6cc10578ddd9bc15b4c0130477210362c6526a9 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Wed, 28 Dec 2022 12:14:33 +0100 Subject: [PATCH] repair snapshots: Always sanitize file nodes If the node for a file is intact, this is a no-op. --- cmd/restic/cmd_repair_snapshots.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/cmd/restic/cmd_repair_snapshots.go b/cmd/restic/cmd_repair_snapshots.go index 036338161..58da8132a 100644 --- a/cmd/restic/cmd_repair_snapshots.go +++ b/cmd/restic/cmd_repair_snapshots.go @@ -107,7 +107,7 @@ func runRepairSnapshots(ctx context.Context, gopts GlobalOptions, opts RepairOpt } ok := true - var newContent restic.IDs + var newContent restic.IDs = restic.IDs{} var newSize uint64 // check all contents and remove if not available for _, id := range node.Content { @@ -119,15 +119,13 @@ func runRepairSnapshots(ctx context.Context, gopts GlobalOptions, opts RepairOpt } } if !ok { - if newSize == 0 { - Printf("removed defective file '%v'\n", path+node.Name) - node = nil - } else { - Printf("repaired defective file '%v'\n", path+node.Name) - node.Content = newContent - node.Size = newSize - } + Verbosef(" file %q: removed missing content\n", path) + } else if newSize != node.Size { + Verbosef(" file %q: fixed incorrect size\n", path) } + // no-ops if already correct + node.Content = newContent + node.Size = newSize return node }, RewriteFailedTree: func(nodeID restic.ID, path string, _ error) (restic.ID, error) {