Add ExpirePolicy.Empty()

This commit is contained in:
Alexander Neumann 2016-08-20 17:51:48 +02:00
parent bf47dba1c4
commit 71f7f4f543
1 changed files with 8 additions and 3 deletions

View File

@ -67,7 +67,13 @@ type ExpirePolicy struct {
// Sum returns the maximum number of snapshots to be kept according to this // Sum returns the maximum number of snapshots to be kept according to this
// policy. // policy.
func (e ExpirePolicy) Sum() int { func (e ExpirePolicy) Sum() int {
return e.Last + e.Daily + e.Weekly + e.Monthly + e.Yearly return e.Last + e.Hourly + e.Daily + e.Weekly + e.Monthly + e.Yearly
}
// Empty returns true iff no policy has been configured (all values zero).
func (e ExpirePolicy) Empty() bool {
empty := ExpirePolicy{}
return e == empty
} }
// filter is used to split a list of snapshots into those to keep and those to // filter is used to split a list of snapshots into those to keep and those to
@ -175,8 +181,7 @@ func (f *filter) finish() {
func ApplyPolicy(list Snapshots, p ExpirePolicy) (keep, remove Snapshots) { func ApplyPolicy(list Snapshots, p ExpirePolicy) (keep, remove Snapshots) {
sort.Sort(list) sort.Sort(list)
empty := ExpirePolicy{} if p.Empty() {
if p == empty {
return list, remove return list, remove
} }