mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-22 16:34:32 +01:00
d684302864
tests expected that a KeepRule returns a *keep* list whereas it actually returns a *destroy* list.
33 lines
548 B
Go
33 lines
548 B
Go
package pruning
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"sort"
|
|
)
|
|
|
|
type KeepLastN struct {
|
|
n int
|
|
}
|
|
|
|
func NewKeepLastN(n int) (*KeepLastN, error) {
|
|
if n <= 0 {
|
|
return nil, errors.Errorf("must specify positive number as 'keep last count', got %d", n)
|
|
}
|
|
return &KeepLastN{n}, nil
|
|
}
|
|
|
|
func (k KeepLastN) KeepRule(snaps []Snapshot) (destroyList []Snapshot) {
|
|
|
|
if k.n > len(snaps) {
|
|
return []Snapshot{}
|
|
}
|
|
|
|
res := shallowCopySnapList(snaps)
|
|
|
|
sort.Slice(res, func(i, j int) bool {
|
|
return res[i].Date().After(res[j].Date())
|
|
})
|
|
|
|
return res[k.n:]
|
|
}
|