zfs: ZFSListMapping fix broken logic

This commit is contained in:
Christian Schwarz 2017-05-06 23:45:33 +02:00
parent cb37470010
commit 44d20ac256

View File

@ -21,9 +21,9 @@ func ZFSListMapping(mapping DatasetMapping) (datasets []DatasetPath, err error)
var lines [][]string var lines [][]string
lines, err = ZFSList([]string{"name"}, "-r", "-t", "filesystem,volume") lines, err = ZFSList([]string{"name"}, "-r", "-t", "filesystem,volume")
datasets = make([]DatasetPath, len(lines)) datasets = make([]DatasetPath, 0, len(lines))
for i, line := range lines { for _, line := range lines {
var path DatasetPath var path DatasetPath
if path, err = NewDatasetPath(line[0]); err != nil { if path, err = NewDatasetPath(line[0]); err != nil {
@ -31,12 +31,12 @@ func ZFSListMapping(mapping DatasetMapping) (datasets []DatasetPath, err error)
} }
_, mapErr := mapping.Map(path) _, mapErr := mapping.Map(path)
if mapErr != nil && err != NoMatchError { if mapErr != nil && mapErr != NoMatchError {
return nil, err return nil, mapErr
} }
if mapErr == nil { if mapErr == nil {
datasets[i] = path datasets = append(datasets, path)
} }
} }