From ebc46cf1c04a00ee779013d3e72dab07fce454e3 Mon Sep 17 00:00:00 2001 From: Denis Shaposhnikov <993498+dsh2dsh@users.noreply.github.com> Date: Fri, 22 Dec 2023 13:38:14 +0100 Subject: [PATCH] Fix last_n keep rule (#691) (#750) From https://github.com/zrepl/zrepl/issues/691 The last_n prune rule keeps everything, regardless of if it matches the regex or not, if there are less than count snapshot. The expectation would be to never keep non-regex snapshots, regardless of number. --- pruning/keep_last_n.go | 5 ----- pruning/keep_last_n_test.go | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/pruning/keep_last_n.go b/pruning/keep_last_n.go index 023568d..73f00cc 100644 --- a/pruning/keep_last_n.go +++ b/pruning/keep_last_n.go @@ -33,11 +33,6 @@ func NewKeepLastN(n int, regex string) (*KeepLastN, error) { } func (k KeepLastN) KeepRule(snaps []Snapshot) (destroyList []Snapshot) { - - if k.n > len(snaps) { - return []Snapshot{} - } - matching, notMatching := partitionSnapList(snaps, func(snapshot Snapshot) bool { return k.re.MatchString(snapshot.Name()) }) diff --git a/pruning/keep_last_n_test.go b/pruning/keep_last_n_test.go index 4283e3e..17e7394 100644 --- a/pruning/keep_last_n_test.go +++ b/pruning/keep_last_n_test.go @@ -90,7 +90,7 @@ func TestKeepLastN(t *testing.T) { stubSnap{"a2", false, o(12)}, }, rules: []KeepRule{ - MustKeepLastN(3, "a"), + MustKeepLastN(4, "a"), }, expDestroy: map[string]bool{ "b1": true,