move cmd/pruning to pruning, as it's independent of the command implementation

This commit is contained in:
Christian Schwarz
2018-08-27 16:11:35 +02:00
parent fb0a8d8b40
commit 0de17fd051
9 changed files with 0 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
package pruning
import (
"time"
)
type KeepRule interface {
KeepRule(snaps []Snapshot) []Snapshot
}
type Snapshot interface {
Name() string
Replicated() bool
Date() time.Time
}
func PruneSnapshots(snaps []Snapshot, keepRules []KeepRule) []Snapshot {
if len(keepRules) == 0 {
return snaps
}
remCount := make(map[Snapshot]int, len(snaps))
for _, r := range keepRules {
ruleRems := r.KeepRule(snaps)
for _, ruleRem := range ruleRems {
remCount[ruleRem]++
}
}
remove := make([]Snapshot, 0, len(snaps))
for snap, rc := range remCount {
if rc == len(keepRules) {
remove = append(remove, snap)
}
}
return remove
}