Skip to content

Commit

Permalink
mount: add option to specify squashfuse path
Browse files Browse the repository at this point in the history
Fixes apptainer#204

Signed-off-by: Edita Kizinevic <edita.kizinevic@cern.ch>
  • Loading branch information
dtrudg authored and edytuk committed May 10, 2022
1 parent d5a82b9 commit 6634305
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions internal/pkg/exp/mount.go
Expand Up @@ -30,8 +30,8 @@ func mountSquashFS(ctx context.Context, offset int64, path, mountPath string, mo
filepath.Clean(path),
filepath.Clean(mountPath),
}

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

Expand All @@ -44,8 +44,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 @@ -67,15 +68,34 @@ func OptMountStderr(w io.Writer) MountOpt {
}
}

var errSquashfusePathInvalid = errors.New("squashfuse path must be relative or absolute")

// OptMountSquashfusePath sets an explicit path to the squashfuse binary. The path must be an
// absolute or relative path.
func OptMountSquashfusePath(path string) MountOpt {
return func(mo *mountOpts) error {
if filepath.Base(path) == path {
return errSquashfusePathInvalid
}
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.
//
// Mount may start one or more underlying processes. By default, stdout and stderr of these
// processes is discarded. To modify this behavior, consider using OptMountStdout and/or
// OptMountStderr.
//
// By default, Mount searches for a squashfuse binary in the directories named by the PATH
// environment variable. To override this behavior, consider using OptMountSquashfusePath().
func Mount(ctx context.Context, path, mountPath string, opts ...MountOpt) error {
mo := mountOpts{}
mo := mountOpts{
squashfusePath: "squashfuse",
}

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

0 comments on commit 6634305

Please sign in to comment.