Skip to content

Commit 87c7159

Browse files
committed
blockdev: Use /sysroot as fallback in get_devices() if
`/boot` is not mounted Inspired by #855 (comment) If `/boot` is not mounted, the parent devices of `/sysroot` will be used as a fallback.
1 parent b3a1dc8 commit 87c7159

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

src/blockdev.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,38 @@
11
use camino::Utf8Path;
22
use std::path::Path;
33

4-
use anyhow::{bail, Context, Result};
4+
use anyhow::{Context, Result};
55
use bootc_blockdev::PartitionTable;
66
use fn_error_context::context;
77

8-
#[context("get parent devices from mount point boot")]
8+
#[context("get parent devices from mount point boot or sysroot")]
99
pub fn get_devices<P: AsRef<Path>>(target_root: P) -> Result<Vec<String>> {
1010
let target_root = target_root.as_ref();
11-
let bootdir = target_root.join("boot");
12-
if !bootdir.exists() {
13-
bail!("{} does not exist", bootdir.display());
11+
let mut source = None;
12+
13+
for path in ["boot", "sysroot"] {
14+
let target_path = target_root.join(path);
15+
if !target_path.exists() {
16+
continue;
17+
}
18+
19+
let target_dir = openat::Dir::open(&target_path)
20+
.with_context(|| format!("Opening {}", target_path.display()))?;
21+
if let Ok(fsinfo) = crate::filesystem::inspect_filesystem(&target_dir, ".") {
22+
source = Some(fsinfo.source);
23+
break;
24+
}
1425
}
15-
let bootdir = openat::Dir::open(&bootdir)?;
16-
// Run findmnt to get the source path of mount point boot
17-
let fsinfo = crate::filesystem::inspect_filesystem(&bootdir, ".")?;
26+
27+
let source = match source {
28+
Some(s) => s,
29+
None => anyhow::bail!("Failed to inspect filesystem from boot or sysroot"),
30+
};
31+
1832
// Find the parent devices of the source path
19-
let parent_devices = bootc_blockdev::find_parent_devices(&fsinfo.source)
20-
.with_context(|| format!("while looking for backing devices of {}", fsinfo.source))?;
21-
log::debug!("Find parent devices: {parent_devices:?}");
33+
let parent_devices = bootc_blockdev::find_parent_devices(&source)
34+
.with_context(|| format!("While looking for backing devices of {}", source))?;
35+
log::debug!("Found parent devices: {parent_devices:?}");
2236
Ok(parent_devices)
2337
}
2438

src/util.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,6 @@ use std::process::Command;
55
use anyhow::{bail, Context, Result};
66
use openat_ext::OpenatDirExt;
77

8-
pub(crate) trait CommandRunExt {
9-
fn run(&mut self) -> Result<()>;
10-
}
11-
12-
impl CommandRunExt for Command {
13-
fn run(&mut self) -> Result<()> {
14-
let r = self.status()?;
15-
if !r.success() {
16-
bail!("Child [{:?}] exited: {}", self, r);
17-
}
18-
Ok(())
19-
}
20-
}
21-
228
/// Parse an environment variable as UTF-8
239
#[allow(dead_code)]
2410
pub(crate) fn getenv_utf8(n: &str) -> Result<Option<String>> {

0 commit comments

Comments
 (0)