|
1 | 1 | use camino::Utf8Path; |
2 | 2 | use std::path::Path; |
3 | 3 |
|
4 | | -use anyhow::{bail, Context, Result}; |
| 4 | +use anyhow::{Context, Result}; |
5 | 5 | use bootc_blockdev::PartitionTable; |
6 | 6 | use fn_error_context::context; |
7 | 7 |
|
8 | | -#[context("get parent devices from mount point boot")] |
| 8 | +#[context("get parent devices from mount point boot or sysroot")] |
9 | 9 | pub fn get_devices<P: AsRef<Path>>(target_root: P) -> Result<Vec<String>> { |
10 | 10 | 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 | + } |
14 | 25 | } |
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 | + |
18 | 32 | // 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:?}"); |
22 | 36 | Ok(parent_devices) |
23 | 37 | } |
24 | 38 |
|
|
0 commit comments