diff --git a/cmd/atomfs/mount.go b/cmd/atomfs/mount.go index 22df8c2..a0bbb93 100644 --- a/cmd/atomfs/mount.go +++ b/cmd/atomfs/mount.go @@ -70,7 +70,12 @@ func doMount(ctx *cli.Context) error { os.Exit(1) } target := ctx.Args()[1] - metadir := filepath.Join(target, "meta") + absTarget, err := filepath.Abs(target) + if err != nil { + return err + } + + metadir := filepath.Join("/run", "atomfs", "meta", ReplacePathSeparators(absTarget)) complete := false @@ -92,12 +97,24 @@ func doMount(ctx *cli.Context) error { if err = EnsureDir(rodest); err != nil { return err } + absOCIDir, err := filepath.Abs(ocidir) + if err != nil { + return err + } + absMetadir, err := filepath.Abs(metadir) + if err != nil { + return err + } + absRODest, err := filepath.Abs(rodest) + if err != nil { + return err + } opts := atomfs.MountOCIOpts{ - OCIDir: ocidir, - MetadataPath: metadir, + OCIDir: absOCIDir, + MetadataPath: absMetadir, Tag: tag, - Target: rodest, + Target: absRODest, } mol, err := atomfs.BuildMoleculeFromOCI(opts) diff --git a/cmd/atomfs/umount.go b/cmd/atomfs/umount.go index a889f09..fbe86de 100644 --- a/cmd/atomfs/umount.go +++ b/cmd/atomfs/umount.go @@ -50,11 +50,12 @@ func doUmount(ctx *cli.Context) error { errs = append(errs, fmt.Errorf("Failed unmounting %s: %v", mountpoint, err)) } - // Now that we've unmounted the mountpoint, we expect the following - // under there: - // $mountpoint/meta/ro - the original readonly overlay mountpoint - // $mountpoint/meta/mounts/* - the original squashfs mounts - metadir := filepath.Join(mountpoint, "meta") + // We expect the following in the metadir + // + // $metadir/ro - the original readonly overlay mountpoint + // $metadir/meta/mounts/* - the original squashfs mounts + // $metadir/meta/config.json + metadir := filepath.Join("/run/atomfs/meta", ReplacePathSeparators(mountpoint)) p := filepath.Join(metadir, "ro") err = syscall.Unmount(p, 0) if err != nil { @@ -65,7 +66,7 @@ func doUmount(ctx *cli.Context) error { mounts, err := os.ReadDir(mountsdir) if err != nil { errs = append(errs, fmt.Errorf("Failed reading list of mounts: %v", err)) - return fmt.Errorf("Encountered errors: %#v", errs) + return fmt.Errorf("Encountered errors: %v", errs) } for _, m := range mounts { diff --git a/cmd/atomfs/utils.go b/cmd/atomfs/utils.go index dc811fb..0c0fa5f 100644 --- a/cmd/atomfs/utils.go +++ b/cmd/atomfs/utils.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "strings" ) func EnsureDir(dir string) error { @@ -20,3 +21,12 @@ func PathExists(d string) bool { } return true } + +// remove dir separators to make one dir name. It is OK that this can't be +// cleanly backed out, we don't need it to +func ReplacePathSeparators(p string) string { + if p[0] == '/' { + p = p[1:] + } + return strings.ReplaceAll(p, "/", "-") +}