From fc0c6951d7ac36dd8f30ace929991197dc99ae54 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 5 Aug 2026 23:22:25 -0500 Subject: Simplify: centralize paths in layout, dedup zfs snapshot refs, remove dead code - Add layout.Config methods (ReleasesDir, PostReceiveHookPath, RCScriptPath, RCConfPath) so main.go and jailmgr no longer hand-build paths that layout already owns. - Extract zfsutil.snapRef to replace three inline dataset@tag Sprintfs. - Remove seven unused exported functions (zfsutil.Exists, jailmgr.Stop, sh.RunWithStdinFile, and four dead layout.Config path methods) and their now-unused imports. --- internal/zfsutil/zfsutil.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'internal/zfsutil/zfsutil.go') 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. -- cgit v1.3