diff --git a/cmd/restic/cmd_forget.go b/cmd/restic/cmd_forget.go index c00ff1dd5..d2ddd5386 100644 --- a/cmd/restic/cmd_forget.go +++ b/cmd/restic/cmd_forget.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "strconv" + "sync" "github.com/restic/restic/internal/data" "github.com/restic/restic/internal/errors" @@ -317,10 +318,13 @@ func runForget(ctx context.Context, opts ForgetOptions, pruneOptions PruneOption if len(removeSnIDs) > 0 { if !opts.DryRun { bar := printer.NewCounter("files deleted") + var lock sync.Mutex err := restic.ParallelRemove(ctx, repo, removeSnIDs, restic.WriteableSnapshotFile, func(id restic.ID, err error) error { if err != nil { printer.E("unable to remove %v/%v from the repository\n", restic.SnapshotFile, id) + lock.Lock() failedSnIDs.Insert(id) + lock.Unlock() } else { printer.VV("removed %v/%v\n", restic.SnapshotFile, id) }