mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-21 16:03:32 +01:00
zfs: glob mapping for complete wildcard ("*")
This commit is contained in:
parent
2e6dc26993
commit
ac5a911c64
@ -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) {
|
||||
|
||||
m1 := GlobMapping{
|
||||
|
23
zfs/zfs.go
23
zfs/zfs.go
@ -35,7 +35,16 @@ func (p DatasetPath) ToString() string {
|
||||
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) {
|
||||
if s == "" {
|
||||
return EmptyDatasetPath, nil // the empty dataset path
|
||||
}
|
||||
// TODO validation
|
||||
return toDatasetPath(s), nil
|
||||
}
|
||||
@ -60,11 +69,17 @@ var ZFS_BINARY string = "zfs"
|
||||
func zfsList(root string, filter DatasetFilter) (datasets []DatasetPath, err error) {
|
||||
|
||||
const ZFS_LIST_FIELD_COUNT = 1
|
||||
|
||||
cmd := exec.Command(ZFS_BINARY, "list", "-H", "-r",
|
||||
args := make([]string, 0, 10)
|
||||
args = append(args,
|
||||
"list", "-H", "-r",
|
||||
"-t", "filesystem,volume",
|
||||
"-o", "name",
|
||||
root)
|
||||
"-o", "name")
|
||||
|
||||
if len(root) > 0 {
|
||||
args = append(args, root)
|
||||
}
|
||||
|
||||
cmd := exec.Command(ZFS_BINARY, args...)
|
||||
|
||||
var stdout io.Reader
|
||||
var stderr io.Reader
|
||||
|
Loading…
Reference in New Issue
Block a user