Skip to content

Commit 6ebaf42

Browse files
committed
blockdev: add PARENT_DEVICES
As `PARENT_DEVICES` is used multiple times, initialize once at the begining and read them then, add this in `get_parent_devices()` according to #923 (comment)
1 parent 12011d3 commit 6ebaf42

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/blockdev.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
use camino::Utf8Path;
22
use std::path::Path;
3+
use std::sync::OnceLock;
34

45
use anyhow::{bail, Context, Result};
56
use bootc_blockdev::PartitionTable;
67
use fn_error_context::context;
78

9+
/// Get parent devices and save
10+
pub fn get_parent_devices(devices: Option<Vec<String>>) -> &'static [String] {
11+
static PARENT_DEVICES: OnceLock<Vec<String>> = OnceLock::new();
12+
PARENT_DEVICES.get_or_init(|| devices.unwrap())
13+
}
14+
815
#[context("get parent devices from mount point boot")]
916
pub fn get_devices<P: AsRef<Path>>(target_root: P) -> Result<Vec<String>> {
1017
let target_root = target_root.as_ref();

src/cli/bootupctl.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::bootupd;
2-
use anyhow::Result;
2+
use anyhow::{Context, Result};
33
use clap::Parser;
44
use log::LevelFilter;
55

@@ -129,13 +129,15 @@ impl CtlCommand {
129129
/// Runner for `update` verb.
130130
fn run_update() -> Result<()> {
131131
ensure_running_in_systemd()?;
132-
bootupd::client_run_update()
132+
let sysroot = prep_before_update()?;
133+
bootupd::client_run_update(&sysroot)
133134
}
134135

135136
/// Runner for `update` verb.
136137
fn run_adopt_and_update() -> Result<()> {
137138
ensure_running_in_systemd()?;
138-
bootupd::client_run_adopt_and_update()
139+
let sysroot = prep_before_update()?;
140+
bootupd::client_run_adopt_and_update(&sysroot)
139141
}
140142

141143
/// Runner for `validate` verb.
@@ -213,3 +215,14 @@ fn run_status_in_container(json_format: bool) -> Result<()> {
213215
}
214216
Ok(())
215217
}
218+
219+
/// Initialize parent devices to prepare the update
220+
fn prep_before_update() -> Result<openat::Dir> {
221+
let sysroot = openat::Dir::open("/").context("Opening root dir")?;
222+
let devices = crate::blockdev::get_devices("/").context("get parent devices")?;
223+
// initialize parent devices before update
224+
crate::blockdev::get_parent_devices(Some(devices));
225+
// check if we can get value
226+
crate::blockdev::get_parent_devices(None);
227+
Ok(sysroot)
228+
}

0 commit comments

Comments
 (0)