Skip to content

Commit

Permalink
fix: Fixes mount failure when subdirectory in chroot does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
korewaChino committed Jul 5, 2024
1 parent 308b75f commit 9b67d69
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tiffin"
description = "A minimal container runtime for Linux for setting up chroot-like environments"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
keywords = ["container", "runtime", "chroot", "linux", "nix"]
license = "MIT"
Expand Down
11 changes: 10 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,23 @@ impl MountTarget {
}
}

#[tracing::instrument]
pub fn mount(
&self,
source: &PathBuf,
root: &Path,
) -> Result<UnmountDrop<Mount>, Box<dyn Error>> {
// sanitize target path
let target = self.target.strip_prefix("/").unwrap_or(&self.target);
let target = root.join(target).canonicalize()?;
tracing::info!(?root, "Mounting {:?} to {:?}", source, target);
let target = {
let t = root.join(target);
if !target.exists() {
// create the target directory
std::fs::create_dir_all(&target)?;
}
t
};

std::fs::create_dir_all(&target)?;

Expand Down

0 comments on commit 9b67d69

Please sign in to comment.