From 0cfdb82ea4d445fd60ac39c6738831909a536bef Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Tue, 7 Dec 2021 20:45:36 +0100 Subject: [PATCH] prune: Handle --max-repack-size=0 as expected Previously the flag was ignored and `--max-repack-size=1` had to be used. --- changelog/unreleased/pull-3591 | 8 ++++++++ cmd/restic/cmd_prune.go | 7 ++----- 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 changelog/unreleased/pull-3591 diff --git a/changelog/unreleased/pull-3591 b/changelog/unreleased/pull-3591 new file mode 100644 index 000000000..c533233c9 --- /dev/null +++ b/changelog/unreleased/pull-3591 @@ -0,0 +1,8 @@ +Bugfix: Fix handling of `prune --max-repack-size=0` + +Restic ignored the `--max-repack-size` option when passing a value of 0. This +has been fixed. + +As a workaround, `--max-repack-size=1` can be used with older versions of restic. + +https://github.com/restic/restic/pull/3591 diff --git a/cmd/restic/cmd_prune.go b/cmd/restic/cmd_prune.go index d621afdad..82635f21a 100644 --- a/cmd/restic/cmd_prune.go +++ b/cmd/restic/cmd_prune.go @@ -66,6 +66,7 @@ func addPruneOptions(c *cobra.Command) { } func verifyPruneOptions(opts *PruneOptions) error { + opts.MaxRepackBytes = math.MaxUint64 if len(opts.MaxRepackSize) > 0 { size, err := parseSizeStr(opts.MaxRepackSize) if err != nil { @@ -418,11 +419,7 @@ func prune(opts PruneOptions, gopts GlobalOptions, repo restic.Repository, usedB for _, p := range repackCandidates { reachedUnusedSizeAfter := (stats.size.unused-stats.size.remove-stats.size.repackrm < maxUnusedSizeAfter) - - reachedRepackSize := false - if opts.MaxRepackBytes > 0 { - reachedRepackSize = stats.size.repack+p.unusedSize+p.usedSize > opts.MaxRepackBytes - } + reachedRepackSize := stats.size.repack+p.unusedSize+p.usedSize >= opts.MaxRepackBytes switch { case reachedRepackSize: