config: fix broken parsing of direct mapping

Would only parse wildcard ('|') DirectMapping but no specific direct
mappings.
This commit is contained in:
Christian Schwarz 2017-05-01 20:07:57 +02:00
parent b87829817a
commit 301be177ea

View File

@ -285,23 +285,7 @@ func parseComboMapping(m map[string]string) (c zfs.ComboMapping, err error) {
for lhs, rhs := range m { for lhs, rhs := range m {
if lhs == "|" { if lhs == "*" && strings.HasPrefix(rhs, "!") {
if len(m) != 1 {
err = errors.New("non-recursive mapping must be the only mapping for a sink")
}
m := zfs.DirectMapping{
Source: nil,
}
if m.Target, err = zfs.NewDatasetPath(rhs); err != nil {
return
}
c.Mappings = append(c.Mappings, m)
} else if lhs == "*" && strings.HasPrefix(rhs, "!") {
m := zfs.ExecMapping{} m := zfs.ExecMapping{}
fields := strings.Fields(strings.TrimPrefix(rhs, "!")) fields := strings.Fields(strings.TrimPrefix(rhs, "!"))
@ -329,6 +313,24 @@ func parseComboMapping(m map[string]string) (c zfs.ComboMapping, err error) {
c.Mappings = append(c.Mappings, m) c.Mappings = append(c.Mappings, m)
} else {
m := zfs.DirectMapping{}
if lhs == "|" {
m.Source = nil
} else {
if m.Source, err = zfs.NewDatasetPath(lhs); err != nil {
return
}
}
if m.Target, err = zfs.NewDatasetPath(rhs); err != nil {
return
}
c.Mappings = append(c.Mappings, m)
} }
} }