Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mount: Factor out a run_findmnt helper #367

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading