mirror of
https://github.com/zrepl/zrepl.git
synced 2024-12-29 10:28:53 +01:00
8cca0a8547
Summary: * Logging is still bad * test output in a lot of placed * FIXMEs every where Test Plan: None, just review Differential Revision: https://phabricator.cschwarz.com/D2
37 lines
844 B
Go
37 lines
844 B
Go
package cmd
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"github.com/zrepl/zrepl/zfs"
|
|
"strings"
|
|
)
|
|
|
|
type PrefixFilter struct {
|
|
prefix string
|
|
fstype zfs.VersionType
|
|
fstypeSet bool // optionals anyone?
|
|
}
|
|
|
|
func NewPrefixFilter(prefix string) *PrefixFilter {
|
|
return &PrefixFilter{prefix: prefix}
|
|
}
|
|
|
|
func NewTypedPrefixFilter(prefix string, versionType zfs.VersionType) *PrefixFilter {
|
|
return &PrefixFilter{prefix, versionType, true}
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
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
|
|
}
|