summaryrefslogtreecommitdiff
path: root/internal/zfsutil
diff options
context:
space:
mode:
Diffstat (limited to 'internal/zfsutil')
-rw-r--r--internal/zfsutil/zfsutil.go12
1 files changed, 5 insertions, 7 deletions
diff --git a/internal/zfsutil/zfsutil.go b/internal/zfsutil/zfsutil.go
index 3d3bd40..8f1b0e2 100644
--- a/internal/zfsutil/zfsutil.go
+++ b/internal/zfsutil/zfsutil.go
@@ -11,20 +11,18 @@ import (
"skiff/internal/sh"
)
-func Exists(ctx context.Context, dataset string) bool {
- _, err := sh.Output(ctx, "", "zfs", "list", "-H", "-o", "name", dataset)
- return err == nil
+func snapRef(dataset, tag string) string {
+ return fmt.Sprintf("%s@%s", dataset, tag)
}
// Clone creates a new dataset from a (read-only) snapshot of base, mounted
// at mountpoint. base must already have a snapshot named baseSnapshot.
func Clone(ctx context.Context, out io.Writer, base, baseSnapshot, dataset, mountpoint string) error {
- src := fmt.Sprintf("%s@%s", base, baseSnapshot)
- return sh.Run(ctx, out, "", "zfs", "clone", "-o", "mountpoint="+mountpoint, src, dataset)
+ return sh.Run(ctx, out, "", "zfs", "clone", "-o", "mountpoint="+mountpoint, snapRef(base, baseSnapshot), dataset)
}
func Snapshot(ctx context.Context, out io.Writer, dataset, tag string) error {
- return sh.Run(ctx, out, "", "zfs", "snapshot", fmt.Sprintf("%s@%s", dataset, tag))
+ return sh.Run(ctx, out, "", "zfs", "snapshot", snapRef(dataset, tag))
}
// Rollback discards everything written to dataset since the snapshot named
@@ -32,7 +30,7 @@ func Snapshot(ctx context.Context, out io.Writer, dataset, tag string) error {
// used both for the automatic post-health-check-failure rollback and for a
// manual `skiff rollback` days later.
func Rollback(ctx context.Context, out io.Writer, dataset, tag string) error {
- return sh.Run(ctx, out, "", "zfs", "rollback", "-r", fmt.Sprintf("%s@%s", dataset, tag))
+ return sh.Run(ctx, out, "", "zfs", "rollback", "-r", snapRef(dataset, tag))
}
// Snapshots lists snapshot names (without the dataset@ prefix), newest last.