From f1507ea0bb1a440b0df87a2a242edbfc996f6b6e Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 17 Nov 2020 18:35:47 +0000 Subject: [PATCH] Thread sysroot through adopt+update flow More prep for https://github.com/coreos/bootupd/issues/108 Similar to the previous PR for updates. --- src/bootupd.rs | 8 ++++---- src/component.rs | 6 +++++- src/efi.rs | 11 ++++++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/bootupd.rs b/src/bootupd.rs index 324bd938..c9411c50 100644 --- a/src/bootupd.rs +++ b/src/bootupd.rs @@ -142,14 +142,14 @@ pub(crate) fn adopt_and_update(name: &str) -> Result { } else { anyhow::bail!("Component {} has no available update", name); }; + let mut state_guard = SavedState::acquire_write_lock(openat::Dir::open("/")?) + .context("Failed to acquire write lock")?; + let inst = component - .adopt_update(&update) + .adopt_update(&state_guard.sysroot, &update) .context("Failed adopt and update")?; state.installed.insert(component.name().into(), inst); - let sysroot = openat::Dir::open("/")?; - let mut state_guard = - SavedState::acquire_write_lock(sysroot).context("Failed to acquire write lock")?; state_guard.update_state(&state)?; Ok(update) } diff --git a/src/component.rs b/src/component.rs index 5fef488e..2b056e9d 100644 --- a/src/component.rs +++ b/src/component.rs @@ -30,7 +30,11 @@ pub(crate) trait Component { fn query_adopt(&self) -> Result>; /// Given an adoptable system and an update, perform the update. - fn adopt_update(&self, update: &ContentMetadata) -> Result; + fn adopt_update( + &self, + sysroot: &openat::Dir, + update: &ContentMetadata, + ) -> Result; /// Implementation of `bootupd install` for a given component. This should /// gather data (or run binaries) from the source root, and install them diff --git a/src/efi.rs b/src/efi.rs index 9ae31c8c..9e0614b3 100644 --- a/src/efi.rs +++ b/src/efi.rs @@ -74,7 +74,11 @@ impl Component for EFI { } /// Given an adoptable system and an update, perform the update. - fn adopt_update(&self, updatemeta: &ContentMetadata) -> Result { + fn adopt_update( + &self, + sysroot: &openat::Dir, + updatemeta: &ContentMetadata, + ) -> Result { let meta = if let Some(meta) = self.query_adopt()? { meta } else { @@ -83,8 +87,9 @@ impl Component for EFI { let esp = self.open_esp()?; validate_esp(&esp)?; - let updated = - openat::Dir::open(&component_updatedir("/", self)).context("opening update dir")?; + let updated = sysroot + .sub_dir(&component_updatedirname(self)) + .context("opening update dir")?; let updatef = filetree::FileTree::new_from_dir(&updated).context("reading update dir")?; // For adoption, we should only touch files that we know about. let diff = updatef.relative_diff_to(&esp)?;