mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-21 16:03:32 +01:00
[#292] pruning: last_n: use snap name as fallback when creation is equal
This commit is contained in:
parent
91e310b7e3
commit
639359f393
@ -2,6 +2,7 @@ package pruning
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@ -26,7 +27,13 @@ func (k KeepLastN) KeepRule(snaps []Snapshot) (destroyList []Snapshot) {
|
||||
res := shallowCopySnapList(snaps)
|
||||
|
||||
sort.Slice(res, func(i, j int) bool {
|
||||
return res[i].Date().After(res[j].Date())
|
||||
// by date (youngest first)
|
||||
id, jd := res[i].Date(), res[j].Date()
|
||||
if !id.Equal(jd) {
|
||||
return id.After(jd)
|
||||
}
|
||||
// then lexicographically descending (e.g. b, a)
|
||||
return strings.Compare(res[i].Name(), res[j].Name()) == 1
|
||||
})
|
||||
|
||||
return res[k.n:]
|
||||
|
Loading…
Reference in New Issue
Block a user