Skip to content

Commit

Permalink
mount: add option to specify squashfuse path
Browse files Browse the repository at this point in the history
Fixes #204
  • Loading branch information
dtrudg committed Apr 18, 2022
1 parent 5314bc0 commit b4a6c32
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions internal/pkg/exp/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func mountSquashFS(ctx context.Context, offset int64, path, mountPath string, mo
filepath.Clean(path),
filepath.Clean(mountPath),
}

cmd := exec.CommandContext(ctx, "squashfuse", args...)
// note (gosec exclusion) - we require callers to be able to specify squashfuse not on PATH
cmd := exec.CommandContext(ctx, mo.squashfusePath, args...) //nolint:gosec
cmd.Stdout = mo.stdout
cmd.Stderr = mo.stderr

Expand All @@ -40,8 +40,9 @@ func mountSquashFS(ctx context.Context, offset int64, path, mountPath string, mo

// mountOpts accumulates mount options.
type mountOpts struct {
stdout io.Writer
stderr io.Writer
stdout io.Writer
stderr io.Writer
squashfusePath string
}

// MountOpt are used to specify mount options.
Expand All @@ -63,6 +64,14 @@ func OptMountStderr(w io.Writer) MountOpt {
}
}

// OptMountSquashfusePath sets an explicit path to the squashfuse binary.
func OptMountSquashfusePath(path string) MountOpt {
return func(mo *mountOpts) error {
mo.squashfusePath = path
return nil
}
}

var errUnsupportedFSType = errors.New("unrecognized filesystem type")

// Mount mounts the primary system partition of the SIF file at path into mountPath.
Expand All @@ -71,7 +80,10 @@ var errUnsupportedFSType = errors.New("unrecognized filesystem type")
// processes is discarded. To modify this behavior, consider using OptMountStdout and/or
// OptMountStderr.
func Mount(ctx context.Context, path, mountPath string, opts ...MountOpt) error {
mo := mountOpts{}
mo := mountOpts{
// By default we will search for 'squashfuse' on PATH.
squashfusePath: "squashfuse",
}

for _, opt := range opts {
if err := opt(&mo); err != nil {
Expand Down

0 comments on commit b4a6c32

Please sign in to comment.