Skip to content

Commit 1f6cad2

Browse files
committed
Add struct RootContext to gather the context up and pass it down
Make the change according to #923 (comment)
1 parent 12011d3 commit 1f6cad2

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/bootupd.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::efi;
1212
use crate::model::{ComponentStatus, ComponentUpdatable, ContentMetadata, SavedState, Status};
1313
use crate::util;
1414
use anyhow::{anyhow, Context, Result};
15+
use camino::{Utf8Path, Utf8PathBuf};
1516
use clap::crate_version;
1617
use fn_error_context::context;
1718
use libc::mode_t;
@@ -408,6 +409,34 @@ pub(crate) fn print_status(status: &Status) -> Result<()> {
408409
Ok(())
409410
}
410411

412+
pub struct RootContext {
413+
pub sysroot: openat::Dir,
414+
pub path: Utf8PathBuf,
415+
pub devices: Vec<String>
416+
}
417+
418+
impl RootContext {
419+
fn new(sysroot: openat::Dir, path: &str, devices: Vec<String>) -> Self {
420+
Self {
421+
sysroot,
422+
path: Utf8Path::new(path).into(),
423+
devices,
424+
}
425+
}
426+
}
427+
428+
/// Initialize parent devices to prepare the update
429+
fn prep_before_update() -> Result<RootContext> {
430+
let path = "/";
431+
let sysroot = openat::Dir::open(path).context("Opening root dir")?;
432+
let devices = crate::blockdev::get_devices(path).context("get parent devices")?;
433+
Ok(RootContext::new(
434+
sysroot,
435+
path,
436+
devices
437+
))
438+
}
439+
411440
pub(crate) fn client_run_update() -> Result<()> {
412441
crate::try_fail_point!("update");
413442
let status: Status = status()?;

0 commit comments

Comments
 (0)