mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-25 01:44:43 +01:00
42 lines
955 B
Go
42 lines
955 B
Go
package filters
|
|
|
|
import (
|
|
"github.com/zrepl/zrepl/zfs"
|
|
"strings"
|
|
)
|
|
|
|
type AnyFSVFilter struct{}
|
|
|
|
func NewAnyFSVFilter() AnyFSVFilter {
|
|
return AnyFSVFilter{}
|
|
}
|
|
|
|
var _ zfs.FilesystemVersionFilter = AnyFSVFilter{}
|
|
|
|
func (AnyFSVFilter) Filter(t zfs.VersionType, name string) (accept bool, err error) {
|
|
return true, nil
|
|
}
|
|
|
|
|
|
type PrefixFilter struct {
|
|
prefix string
|
|
fstype zfs.VersionType
|
|
fstypeSet bool // optionals anyone?
|
|
}
|
|
|
|
var _ zfs.FilesystemVersionFilter = &PrefixFilter{}
|
|
|
|
func NewPrefixFilter(prefix string) *PrefixFilter {
|
|
return &PrefixFilter{prefix: prefix}
|
|
}
|
|
|
|
func NewTypedPrefixFilter(prefix string, versionType zfs.VersionType) *PrefixFilter {
|
|
return &PrefixFilter{prefix, versionType, true}
|
|
}
|
|
|
|
func (f *PrefixFilter) Filter(t zfs.VersionType, name string) (accept bool, err error) {
|
|
fstypeMatches := (!f.fstypeSet || t == f.fstype)
|
|
prefixMatches := strings.HasPrefix(name, f.prefix)
|
|
return fstypeMatches && prefixMatches, nil
|
|
}
|