pruning/keep_last_n: correctly handle the case where count > matching snaps

fixes #446
This commit is contained in:
Christian Schwarz
2021-03-25 22:36:01 +01:00
parent ac4b109872
commit f661d9429f
2 changed files with 19 additions and 1 deletions
+6 -1
View File
@@ -57,6 +57,11 @@ func (k KeepLastN) KeepRule(snaps []Snapshot) (destroyList []Snapshot) {
// then lexicographically descending (e.g. b, a)
return strings.Compare(matching[i].Name(), matching[j].Name()) == 1
})
destroyList = append(destroyList, matching[k.n:]...)
n := k.n
if n > len(matching) {
n = len(matching)
}
destroyList = append(destroyList, matching[n:]...)
return destroyList
}