mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-22 00:13:52 +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) {
|
func TestComboMapping(t *testing.T) {
|
||||||
|
|
||||||
m1 := GlobMapping{
|
m1 := GlobMapping{
|
||||||
|
23
zfs/zfs.go
23
zfs/zfs.go
@ -35,7 +35,16 @@ func (p DatasetPath) ToString() string {
|
|||||||
return strings.Join(p, "/")
|
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) {
|
func NewDatasetPath(s string) (p DatasetPath, err error) {
|
||||||
|
if s == "" {
|
||||||
|
return EmptyDatasetPath, nil // the empty dataset path
|
||||||
|
}
|
||||||
// TODO validation
|
// TODO validation
|
||||||
return toDatasetPath(s), nil
|
return toDatasetPath(s), nil
|
||||||
}
|
}
|
||||||
@ -60,11 +69,17 @@ var ZFS_BINARY string = "zfs"
|
|||||||
func zfsList(root string, filter DatasetFilter) (datasets []DatasetPath, err error) {
|
func zfsList(root string, filter DatasetFilter) (datasets []DatasetPath, err error) {
|
||||||
|
|
||||||
const ZFS_LIST_FIELD_COUNT = 1
|
const ZFS_LIST_FIELD_COUNT = 1
|
||||||
|
args := make([]string, 0, 10)
|
||||||
cmd := exec.Command(ZFS_BINARY, "list", "-H", "-r",
|
args = append(args,
|
||||||
|
"list", "-H", "-r",
|
||||||
"-t", "filesystem,volume",
|
"-t", "filesystem,volume",
|
||||||
"-o", "name",
|
"-o", "name")
|
||||||
root)
|
|
||||||
|
if len(root) > 0 {
|
||||||
|
args = append(args, root)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := exec.Command(ZFS_BINARY, args...)
|
||||||
|
|
||||||
var stdout io.Reader
|
var stdout io.Reader
|
||||||
var stderr io.Reader
|
var stderr io.Reader
|
||||||
|
Loading…
Reference in New Issue
Block a user