Skip to content

Commit

Permalink
Merge pull request containers#367 from cgwalters/dynamic-mounts
Browse files Browse the repository at this point in the history
mount: Factor out a run_findmnt helper
  • Loading branch information
cgwalters authored Feb 28, 2024
2 parents 34dd356 + a9c5b02 commit db13d83
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/src/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ pub(crate) struct Findmnt {
pub(crate) filesystems: Vec<Filesystem>,
}

#[context("Inspecting filesystem {path}")]
pub(crate) fn inspect_filesystem(path: &Utf8Path) -> Result<Filesystem> {
fn run_findmnt(args: &[&str], path: &str) -> Result<Filesystem> {
let desc = format!("Inspecting {path}");
let o = Task::new(desc, "findmnt")
.args([
"-J",
"-v",
// If you change this you probably also want to change the Filesystem struct above
"--output=SOURCE,FSTYPE,OPTIONS,UUID",
path.as_str(),
])
.args(args)
.arg(path)
.quiet()
.read()?;
let o: Findmnt = serde_json::from_str(&o).context("Parsing findmnt output")?;
Expand All @@ -42,6 +42,13 @@ pub(crate) fn inspect_filesystem(path: &Utf8Path) -> Result<Filesystem> {
.ok_or_else(|| anyhow!("findmnt returned no data for {path}"))
}

#[context("Inspecting filesystem {path}")]
/// Inspect a target which must be a mountpoint root - it is an error
/// if the target is not the mount root.
pub(crate) fn inspect_filesystem(path: &Utf8Path) -> Result<Filesystem> {
run_findmnt(&["--mountpoint"], path.as_str())
}

/// Mount a device to the target path.
pub(crate) fn mount(dev: &str, target: &Utf8Path) -> Result<()> {
Task::new_and_run(
Expand Down

0 comments on commit db13d83

Please sign in to comment.