Skip to content

Commit ebc46cf

Browse files
authored
Fix last_n keep rule (#691) (#750)
From #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.
1 parent 27012e5 commit ebc46cf

File tree

2 files changed

+1
-6
lines changed

2 files changed

+1
-6
lines changed

pruning/keep_last_n.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ func NewKeepLastN(n int, regex string) (*KeepLastN, error) {
3333
}
3434

3535
func (k KeepLastN) KeepRule(snaps []Snapshot) (destroyList []Snapshot) {
36-
37-
if k.n > len(snaps) {
38-
return []Snapshot{}
39-
}
40-
4136
matching, notMatching := partitionSnapList(snaps, func(snapshot Snapshot) bool {
4237
return k.re.MatchString(snapshot.Name())
4338
})

pruning/keep_last_n_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func TestKeepLastN(t *testing.T) {
9090
stubSnap{"a2", false, o(12)},
9191
},
9292
rules: []KeepRule{
93-
MustKeepLastN(3, "a"),
93+
MustKeepLastN(4, "a"),
9494
},
9595
expDestroy: map[string]bool{
9696
"b1": true,

0 commit comments

Comments
 (0)