From 639359f39339606c0eff9d8a98fedd337da1e1a5 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Sat, 29 Aug 2020 17:44:17 +0200 Subject: [PATCH] [#292] pruning: last_n: use snap name as fallback when creation is equal --- pruning/keep_last_n.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pruning/keep_last_n.go b/pruning/keep_last_n.go index 487eaff..3f90d8a 100644 --- a/pruning/keep_last_n.go +++ b/pruning/keep_last_n.go @@ -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:]