zfs: glob mapping for complete wildcard ("*")

This commit is contained in:
Christian Schwarz 2017-04-30 16:13:05 +02:00
parent 2e6dc26993
commit ac5a911c64
2 changed files with 33 additions and 4 deletions

View File

@ -27,6 +27,20 @@ func TestGlobMapping(t *testing.T) {
} }
func TestGlobMappingWildcard(t *testing.T) {
m := GlobMapping{
PrefixPath: EmptyDatasetPath,
TargetRoot: toDatasetPath("backups/share1"),
}
var r DatasetPath
var err error
r, err = m.Map(toDatasetPath("tank/usr/home"))
assert.Equal(t, toDatasetPath("backups/share1/tank/usr/home"), r)
assert.NoError(t, err)
}
func TestComboMapping(t *testing.T) { func TestComboMapping(t *testing.T) {
m1 := GlobMapping{ m1 := GlobMapping{

View File

@ -35,7 +35,16 @@ func (p DatasetPath) ToString() string {
return strings.Join(p, "/") return strings.Join(p, "/")
} }
func (p DatasetPath) Empty() bool {
return len(p) == 0
}
var EmptyDatasetPath DatasetPath = []string{}
func NewDatasetPath(s string) (p DatasetPath, err error) { func NewDatasetPath(s string) (p DatasetPath, err error) {
if s == "" {
return EmptyDatasetPath, nil // the empty dataset path
}
// TODO validation // TODO validation
return toDatasetPath(s), nil return toDatasetPath(s), nil
} }
@ -60,11 +69,17 @@ var ZFS_BINARY string = "zfs"
func zfsList(root string, filter DatasetFilter) (datasets []DatasetPath, err error) { func zfsList(root string, filter DatasetFilter) (datasets []DatasetPath, err error) {
const ZFS_LIST_FIELD_COUNT = 1 const ZFS_LIST_FIELD_COUNT = 1
args := make([]string, 0, 10)
cmd := exec.Command(ZFS_BINARY, "list", "-H", "-r", args = append(args,
"list", "-H", "-r",
"-t", "filesystem,volume", "-t", "filesystem,volume",
"-o", "name", "-o", "name")
root)
if len(root) > 0 {
args = append(args, root)
}
cmd := exec.Command(ZFS_BINARY, args...)
var stdout io.Reader var stdout io.Reader
var stderr io.Reader var stderr io.Reader