mappings: fix aliasing bug with '<' wildcards
In contrast to any 'something<' mapping, a '<' mapping cannot be unique
Thus, '<' mappings are thus just an append to target, which is exactly
what we get when trimming empty prefix ''.
Otherwise, given mapping
{ "<": "storage/backups/app-srv" }
Before (clearly a conflict)
zroot => storage/backups/app-srv
storage => storage/backups/app-srv
After:
zroot => storage/backups/app-srv/zroot
storage => storage/backups/app-srv/storage
However, mapping directly with subtree wildcard is still possible, just
not with the root wildcard
{
"<" "storage/backups/app-srv"
"zroot/var/db<": "storage/db_replication/app-srv"
}
fixes #22
This commit is contained in:
@@ -125,14 +125,9 @@ func (m DatasetMapFilter) Map(source *zfs.DatasetPath) (target *zfs.DatasetPath,
|
||||
return
|
||||
}
|
||||
if me.subtreeMatch {
|
||||
// strip common prefix
|
||||
// strip common prefix ('<' wildcards are no special case here)
|
||||
extendComps := source.Copy()
|
||||
if me.path.Empty() {
|
||||
// special case: trying to map the root => strip first component
|
||||
extendComps.TrimNPrefixComps(1)
|
||||
} else {
|
||||
extendComps.TrimPrefix(me.path)
|
||||
}
|
||||
extendComps.TrimPrefix(me.path)
|
||||
target.Extend(extendComps)
|
||||
}
|
||||
return
|
||||
|
||||
+2
-2
@@ -129,8 +129,8 @@ func TestDatasetMapFilter(t *testing.T) {
|
||||
expectMapping(map1, "a/b/c/d/e", "")
|
||||
expectMapping(map1, "a/b/e", "root2/e")
|
||||
expectMapping(map1, "a/b", "root2")
|
||||
expectMapping(map1, "x", "root3/b/c")
|
||||
expectMapping(map1, "x/y", "root3/b/c/y")
|
||||
expectMapping(map1, "x", "root3/b/c/x")
|
||||
expectMapping(map1, "x/y", "root3/b/c/x/y")
|
||||
expectMapping(map1, "q", "root4/1/2")
|
||||
expectMapping(map1, "b", "")
|
||||
expectMapping(map1, "q/r", "root4/1/2/r")
|
||||
|
||||
Reference in New Issue
Block a user