diff --git a/src/builder/mount.rs b/src/builder/mount.rs index fdfc214..471fb40 100644 --- a/src/builder/mount.rs +++ b/src/builder/mount.rs @@ -40,6 +40,8 @@ impl OCIBuilder { upperdir_path ); + let tmp_path = self.layer_store().overlay_tmp_path(&top_layer_digest); + let mut lowerdir_paths: Vec = Vec::new(); for layer in cnt.rootfs_diff() { @@ -66,7 +68,7 @@ impl OCIBuilder { if lowerdir_paths.is_empty() { mount_options = format!( "lowerdir={},upperdir={},workdir={}", - upperdir_path.display(), + tmp_path.display(), upperdir_path.display(), workdir_path.display(), ); @@ -79,7 +81,7 @@ impl OCIBuilder { ); if nix::unistd::geteuid().as_raw() != 0 { - mount_rootless(&mount_point, lowerdir_paths, &upperdir_path, &workdir_path)? + mount_rootless(&mount_point, &mount_options)? } else { mount(&mount_point, &mount_options)?; } @@ -160,31 +162,10 @@ fn umount(mount_point: &Path) -> BuilderResult<()> { } } -fn mount_rootless( - mount_point: &Path, - lower_dir: Vec, - upper_dir: &Path, - work_dir: &Path, -) -> BuilderResult<()> { - let mut cmd_options = String::new(); - for ldir in lower_dir { - if cmd_options.is_empty() { - cmd_options = format!("lowerdir={}", ldir) - } else { - cmd_options = format!("{}:{}", cmd_options, ldir) - } - } - - cmd_options = format!( - "{},upperdir={},workdir={}", - cmd_options, - upper_dir.display(), - work_dir.display(), - ); - +fn mount_rootless(mount_point: &Path, mount_options: &str) -> BuilderResult<()> { match Command::new("/usr/bin/fuse-overlayfs") .arg("-o") - .arg(cmd_options) + .arg(mount_options) .arg(mount_point.display().to_string()) .output() { diff --git a/src/layer/create.rs b/src/layer/create.rs index 5129c78..a804c30 100644 --- a/src/layer/create.rs +++ b/src/layer/create.rs @@ -25,6 +25,7 @@ impl LayerStore { &self.overlay_diff_path(dg), &self.overlay_rootfs_path(dg), &self.overlay_work_path(dg), + &self.overlay_tmp_path(dg), ]; for dir_path in overlays_subdir { diff --git a/src/layer/store.rs b/src/layer/store.rs index d49e312..2d08e72 100644 --- a/src/layer/store.rs +++ b/src/layer/store.rs @@ -69,4 +69,11 @@ impl LayerStore { work_path.push("work"); work_path } + + pub fn overlay_tmp_path(&self, dg: &digest::Digest) -> PathBuf { + let mut work_path = self.overlay_path.clone(); + work_path.push(&dg.encoded); + work_path.push("tmp"); + work_path + } }