2017-09-10 16:13:05 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2017-09-13 23:27:18 +02:00
|
|
|
"github.com/pkg/errors"
|
2017-09-10 16:13:05 +02:00
|
|
|
"github.com/zrepl/zrepl/zfs"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PrefixSnapshotFilter struct {
|
|
|
|
Prefix string
|
|
|
|
}
|
|
|
|
|
2017-09-13 23:27:18 +02:00
|
|
|
func parseSnapshotPrefix(i string) (p string, err error) {
|
|
|
|
if len(i) <= 0 {
|
|
|
|
err = errors.Errorf("snapshot prefix must not be empty string")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
p = i
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-09-10 16:13:05 +02:00
|
|
|
func parsePrefixSnapshotFilter(i string) (f *PrefixSnapshotFilter, err error) {
|
|
|
|
if !(len(i) > 0) {
|
|
|
|
err = errors.Errorf("snapshot prefix must be longer than 0 characters")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
f = &PrefixSnapshotFilter{i}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *PrefixSnapshotFilter) Filter(fsv zfs.FilesystemVersion) (accept bool, err error) {
|
|
|
|
return fsv.Type == zfs.Snapshot && strings.HasPrefix(fsv.Name, f.Prefix), nil
|
|
|
|
}
|