mirror of
https://github.com/zrepl/zrepl.git
synced 2025-01-05 13:59:06 +01:00
parent
cef63ac176
commit
51af880701
@ -47,7 +47,7 @@ func (a *IntervalAutosnap) Run(ctx context.Context, didSnaps chan struct{}) {
|
|||||||
|
|
||||||
l := a.log.WithField(logFSField, d.ToString())
|
l := a.log.WithField(logFSField, d.ToString())
|
||||||
|
|
||||||
fsvs, err := zfs.ZFSListFilesystemVersions(d, &PrefixSnapshotFilter{a.Prefix})
|
fsvs, err := zfs.ZFSListFilesystemVersions(d, NewTypedPrefixFilter(a.Prefix, zfs.Snapshot))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.WithError(err).Error("cannot list filesystem versions")
|
l.WithError(err).Error("cannot list filesystem versions")
|
||||||
continue
|
continue
|
||||||
|
@ -6,8 +6,18 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PrefixSnapshotFilter struct {
|
type PrefixFilter struct {
|
||||||
Prefix string
|
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) {
|
func parseSnapshotPrefix(i string) (p string, err error) {
|
||||||
@ -19,15 +29,8 @@ func parseSnapshotPrefix(i string) (p string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func parsePrefixSnapshotFilter(i string) (f *PrefixSnapshotFilter, err error) {
|
func (f *PrefixFilter) Filter(fsv zfs.FilesystemVersion) (accept bool, err error) {
|
||||||
if !(len(i) > 0) {
|
fstypeMatches := (!f.fstypeSet || fsv.Type == f.fstype)
|
||||||
err = errors.Errorf("snapshot prefix must be longer than 0 characters")
|
prefixMatches := strings.HasPrefix(fsv.Name, f.prefix)
|
||||||
return
|
return fstypeMatches && prefixMatches, nil
|
||||||
}
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ func (j *LocalJob) JobStart(ctx context.Context) {
|
|||||||
// All local datasets will be passed to its Map() function,
|
// All local datasets will be passed to its Map() function,
|
||||||
// but only those for which a mapping exists will actually be pulled.
|
// but only those for which a mapping exists will actually be pulled.
|
||||||
// We can pay this small performance penalty for now.
|
// We can pay this small performance penalty for now.
|
||||||
handler := NewHandler(log.WithField(logTaskField, "handler"), localPullACL{}, &PrefixSnapshotFilter{j.SnapshotPrefix})
|
handler := NewHandler(log.WithField(logTaskField, "handler"), localPullACL{}, NewPrefixFilter(j.SnapshotPrefix))
|
||||||
|
|
||||||
registerEndpoints(local, handler)
|
registerEndpoints(local, handler)
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ outer:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// construct connection handler
|
// construct connection handler
|
||||||
handler := NewHandler(log, j.Filesystems, &PrefixSnapshotFilter{j.SnapshotPrefix})
|
handler := NewHandler(log, j.Filesystems, NewPrefixFilter(j.SnapshotPrefix))
|
||||||
|
|
||||||
// handle connection
|
// handle connection
|
||||||
rpcServer := rpc.NewServer(rwc)
|
rpcServer := rpc.NewServer(rwc)
|
||||||
|
@ -46,7 +46,8 @@ func (p *Pruner) Run(ctx context.Context) (r []PruneResult, err error) {
|
|||||||
|
|
||||||
log := log.WithField(logFSField, fs.ToString())
|
log := log.WithField(logFSField, fs.ToString())
|
||||||
|
|
||||||
fsversions, err := zfs.ZFSListFilesystemVersions(fs, &PrefixSnapshotFilter{p.SnapshotPrefix})
|
snapshotFilter := NewTypedPrefixFilter(p.SnapshotPrefix, zfs.Snapshot)
|
||||||
|
fsversions, err := zfs.ZFSListFilesystemVersions(fs, snapshotFilter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Error("error listing filesytem versions")
|
log.WithError(err).Error("error listing filesytem versions")
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user