Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass sysroot through updates #109

Merged
merged 1 commit into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/backend/statefile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl SavedState {
/// Write-lock guard for statefile, protecting against concurrent state updates.
#[derive(Debug)]
pub(crate) struct StateLockGuard {
sysroot: openat::Dir,
pub(crate) sysroot: openat::Dir,
lockfile: Option<File>,
}

Expand Down
7 changes: 3 additions & 4 deletions src/bootupd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,14 @@ pub(crate) fn update(name: &str) -> Result<ComponentUpdateResult> {
let mut pending_container = state.pending.take().unwrap_or_default();
let interrupted = pending_container.get(component.name()).cloned();
pending_container.insert(component.name().into(), update.clone());
let sysroot = openat::Dir::open("/")?;
let mut state_guard =
SavedState::acquire_write_lock(sysroot).context("Failed to acquire write lock")?;
let mut state_guard = SavedState::acquire_write_lock(openat::Dir::open("/")?)
.context("Failed to acquire write lock")?;
state_guard
.update_state(&state)
.context("Failed to update state")?;

let newinst = component
.run_update(&inst)
.run_update(&state_guard.sysroot, &inst)
.with_context(|| format!("Failed to update {}", component.name()))?;
state.installed.insert(component.name().into(), newinst);
pending_container.remove(component.name());
Expand Down
16 changes: 12 additions & 4 deletions src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ pub(crate) trait Component {
fn query_update(&self) -> Result<Option<ContentMetadata>>;

/// Used on the client to run an update.
fn run_update(&self, current: &InstalledContent) -> Result<InstalledContent>;
fn run_update(
&self,
sysroot: &openat::Dir,
current: &InstalledContent,
) -> Result<InstalledContent>;

/// Used on the client to validate an installed version.
fn validate(&self, current: &InstalledContent) -> Result<ValidationResult>;
Expand All @@ -67,12 +71,16 @@ pub(crate) fn new_from_name(name: &str) -> Result<Box<dyn Component>> {
Ok(r)
}

/// Returns the path to the payload directory for an available update for
/// a component.
pub(crate) fn component_updatedirname(component: &dyn Component) -> PathBuf {
Path::new(BOOTUPD_UPDATES_DIR).join(component.name())
}

/// Returns the path to the payload directory for an available update for
/// a component.
pub(crate) fn component_updatedir(sysroot: &str, component: &dyn Component) -> PathBuf {
Path::new(sysroot)
.join(BOOTUPD_UPDATES_DIR)
.join(component.name())
Path::new(sysroot).join(component_updatedirname(component))
}

/// Returns the name of the JSON file containing a component's available update metadata installed
Expand Down
11 changes: 8 additions & 3 deletions src/efi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,19 @@ impl Component for EFI {
})
}

fn run_update(&self, current: &InstalledContent) -> Result<InstalledContent> {
fn run_update(
&self,
sysroot: &openat::Dir,
current: &InstalledContent,
) -> Result<InstalledContent> {
let currentf = current
.filetree
.as_ref()
.ok_or_else(|| anyhow::anyhow!("No filetree for installed EFI found!"))?;
let updatemeta = self.query_update()?.expect("update available");
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")?;
let diff = currentf.diff(&updatef)?;
let destdir = openat::Dir::open(&Path::new("/").join(MOUNT_PATH).join("EFI"))
Expand Down