mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-22 16:34:32 +01:00
34 lines
563 B
Go
34 lines
563 B
Go
|
package pruning
|
||
|
|
||
|
import (
|
||
|
"regexp"
|
||
|
)
|
||
|
|
||
|
type KeepRegex struct {
|
||
|
expr *regexp.Regexp
|
||
|
}
|
||
|
|
||
|
var _ KeepRule = &KeepRegex{}
|
||
|
|
||
|
func NewKeepRegex(expr string) (*KeepRegex, error) {
|
||
|
re, err := regexp.Compile(expr)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return &KeepRegex{re}, nil
|
||
|
}
|
||
|
|
||
|
func MustKeepRegex(expr string) *KeepRegex {
|
||
|
k, err := NewKeepRegex(expr)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return k
|
||
|
}
|
||
|
|
||
|
func (k *KeepRegex) KeepRule(snaps []Snapshot) []Snapshot {
|
||
|
return filterSnapList(snaps, func(s Snapshot) bool {
|
||
|
return k.expr.FindStringIndex(s.Name()) == nil
|
||
|
})
|
||
|
}
|