mirror of
https://github.com/zrepl/zrepl.git
synced 2024-12-23 15:38:49 +01:00
cba083cadf
Had to resort to using pointers to zfs.DatasetPath everywhere... Should find a better solution for that.
39 lines
720 B
Go
39 lines
720 B
Go
package zfs
|
|
|
|
import "fmt"
|
|
|
|
type DatasetFilter interface {
|
|
Filter(p *DatasetPath) (pass bool, err error)
|
|
}
|
|
|
|
func ZFSListMapping(filter DatasetFilter) (datasets []*DatasetPath, err error) {
|
|
|
|
if filter == nil {
|
|
panic("filter must not be nil")
|
|
}
|
|
|
|
var lines [][]string
|
|
lines, err = ZFSList([]string{"name"}, "-r", "-t", "filesystem,volume")
|
|
|
|
datasets = make([]*DatasetPath, 0, len(lines))
|
|
|
|
for _, line := range lines {
|
|
|
|
var path *DatasetPath
|
|
if path, err = NewDatasetPath(line[0]); err != nil {
|
|
return
|
|
}
|
|
|
|
pass, filterErr := filter.Filter(path)
|
|
if filterErr != nil {
|
|
return nil, fmt.Errorf("error calling filter: %s", filterErr)
|
|
}
|
|
if pass {
|
|
datasets = append(datasets, path)
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
}
|