From d9dd12acf90c8bbb58048d695a57e6c7900decd9 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Wed, 10 Jun 2026 12:44:21 +0200 Subject: [PATCH] Pick the right default repo for rootless mode --- composefs-run/src/main.rs | 16 ++++++++++++---- composefs-run/src/run.rs | 5 +++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/composefs-run/src/main.rs b/composefs-run/src/main.rs index 5173f72..e391ef6 100644 --- a/composefs-run/src/main.rs +++ b/composefs-run/src/main.rs @@ -284,9 +284,10 @@ impl std::str::FromStr for UserSpec { #[derive(Debug, Parser)] #[clap(name = "cfsrun")] pub(crate) struct Cli { - /// Path to the composefs repository - #[clap(long, default_value = "/sysroot/composefs")] - repo: PathBuf, + /// Path to the composefs repository (default: /sysroot/composefs for root, + /// ~/.var/lib/composefs for rootless) + #[clap(long)] + repo: Option, /// Mount the rootfs read-only #[clap(long)] @@ -422,6 +423,12 @@ fn main() -> Result<()> { let rootless = !rustix::process::geteuid().is_root(); let container_id = format!("composefs-{}", std::process::id()); + let repo_path = match cli.repo.clone() { + Some(path) => path, + None if rootless => composefs::repository::user_path()?, + None => composefs::repository::system_path(), + }; + let image = if let Some(ref rootfs) = cli.rootfs { ensure!( rootfs.is_dir(), @@ -433,7 +440,7 @@ fn main() -> Result<()> { erofs_hex: None, } } else { - let repo = ResolvedRepo::open(&cli.repo)?; + let repo = ResolvedRepo::open(&repo_path)?; repo.resolve_image(cli.image.as_deref().context("No image specified")?)? }; @@ -454,6 +461,7 @@ fn main() -> Result<()> { &container_id, &container_dir, &overlay_dir, + &repo_path, &image, ); diff --git a/composefs-run/src/run.rs b/composefs-run/src/run.rs index 915c74f..679771a 100644 --- a/composefs-run/src/run.rs +++ b/composefs-run/src/run.rs @@ -29,6 +29,7 @@ pub fn run( container_id: &str, container_dir: &Path, overlay_dir: &Path, + repo_path: &Path, image: &ResolvedImage, ) -> Result<()> { if rootless { @@ -60,7 +61,7 @@ pub fn run( mount_rootfs_from_path(rootfs, &rootfs_dir, overlay_dir, cli.read_only, rootless)?; } else if rootless { mount_rootfs_with_fuse( - &cli.repo, + repo_path, image, &rootfs_dir, container_dir, @@ -68,7 +69,7 @@ pub fn run( cli.read_only, )?; } else { - mount_rootfs_with_erofs(&cli.repo, image, &rootfs_dir, overlay_dir, cli.read_only)?; + mount_rootfs_with_erofs(repo_path, image, &rootfs_dir, overlay_dir, cli.read_only)?; } // ── Networking ──────────────────────────────────────────────────────