Skip to content

Commit

Permalink
Merge pull request #23 from navidys/develop
Browse files Browse the repository at this point in the history
fix mount command for scratch containers
  • Loading branch information
navidys authored Nov 24, 2024
2 parents 01e62bd + c3bec59 commit f5a43bc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 25 deletions.
31 changes: 6 additions & 25 deletions src/builder/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = Vec::new();

for layer in cnt.rootfs_diff() {
Expand All @@ -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(),
);
Expand All @@ -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)?;
}
Expand Down Expand Up @@ -160,31 +162,10 @@ fn umount(mount_point: &Path) -> BuilderResult<()> {
}
}

fn mount_rootless(
mount_point: &Path,
lower_dir: Vec<String>,
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()
{
Expand Down
1 change: 1 addition & 0 deletions src/layer/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions src/layer/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit f5a43bc

Please sign in to comment.