zfs: Support foo/bar/* globs

This commit is contained in:
Christian Schwarz 2017-05-20 19:50:24 +02:00
parent 5f84d30972
commit d8adce6110
2 changed files with 26 additions and 1 deletions

View File

@ -64,7 +64,11 @@ func (m GlobMapping) Map(source DatasetPath) (target DatasetPath, err error) {
for si, sc := range source { for si, sc := range source {
target = append(target, sc) target = append(target, sc)
if si < len(m.PrefixPath) { if si < len(m.PrefixPath) {
if sc != m.PrefixPath[si] {
compsMatch := sc == m.PrefixPath[si]
endOfPrefixPath := si == len(m.PrefixPath)-1 && m.PrefixPath[si] == ""
if !(compsMatch || endOfPrefixPath) {
err = NoMatchError err = NoMatchError
return return
} }

View File

@ -5,6 +5,27 @@ import (
"testing" "testing"
) )
func TestGlobMappingPrefixWildcard(t *testing.T) {
m := GlobMapping{
PrefixPath: toDatasetPath("a/b/c/"), // TRAILING empty component!
TargetRoot: toDatasetPath("x/y"),
}
t.Logf("PrefixPath: %#v", m.PrefixPath)
var r DatasetPath
var err error
r, err = m.Map(toDatasetPath("a/b/c"))
assert.NotNil(t, err)
r, err = m.Map(toDatasetPath("a/b/c/d"))
assert.Nil(t, err)
assert.Equal(t, toDatasetPath("x/y/a/b/c/d"), r)
}
func TestGlobMapping(t *testing.T) { func TestGlobMapping(t *testing.T) {
m := GlobMapping{ m := GlobMapping{