mirror of
https://github.com/zrepl/zrepl.git
synced 2025-06-20 09:47:50 +02: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 (
|
import (
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
@ -26,7 +27,13 @@ func (k KeepLastN) KeepRule(snaps []Snapshot) (destroyList []Snapshot) {
|
|||||||
res := shallowCopySnapList(snaps)
|
res := shallowCopySnapList(snaps)
|
||||||
|
|
||||||
sort.Slice(res, func(i, j int) bool {
|
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:]
|
return res[k.n:]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user