diff --git a/cmd/restic/cmd_prune.go b/cmd/restic/cmd_prune.go index 7687a9b83..f6553e9ac 100644 --- a/cmd/restic/cmd_prune.go +++ b/cmd/restic/cmd_prune.go @@ -521,9 +521,6 @@ func decidePackAction(ctx context.Context, opts PruneOptions, gopts GlobalOption } } - // calculate limit for number of unused bytes in the repo after repacking - maxUnusedSizeAfter := opts.maxUnusedBytes(stats.size.used) - // Sort repackCandidates such that packs with highest ratio unused/used space are picked first. // This is equivalent to sorting by unused / total space. // Instead of unused[i] / used[i] > unused[j] / used[j] we use @@ -549,6 +546,9 @@ func decidePackAction(ctx context.Context, opts PruneOptions, gopts GlobalOption stats.size.repackrm += p.unusedSize } + // calculate limit for number of unused bytes in the repo after repacking + maxUnusedSizeAfter := opts.maxUnusedBytes(stats.size.used) + for _, p := range repackCandidates { reachedUnusedSizeAfter := (stats.size.unused-stats.size.remove-stats.size.repackrm < maxUnusedSizeAfter) reachedRepackSize := stats.size.repack+p.unusedSize+p.usedSize >= opts.MaxRepackBytes