Skip to content

Commit 6e1c089

Browse files
cgwaltersopenshift-merge-robot
authored andcommitted
Pass sysroot through updates
In order to fix #108 we need to switch to not assuming `/` as the update source. We do provide the system root as a string in some cases but not all. Let's go fd-relative.
1 parent 875a04a commit 6e1c089

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

src/backend/statefile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl SavedState {
8787
/// Write-lock guard for statefile, protecting against concurrent state updates.
8888
#[derive(Debug)]
8989
pub(crate) struct StateLockGuard {
90-
sysroot: openat::Dir,
90+
pub(crate) sysroot: openat::Dir,
9191
lockfile: Option<File>,
9292
}
9393

src/bootupd.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,14 @@ pub(crate) fn update(name: &str) -> Result<ComponentUpdateResult> {
110110
let mut pending_container = state.pending.take().unwrap_or_default();
111111
let interrupted = pending_container.get(component.name()).cloned();
112112
pending_container.insert(component.name().into(), update.clone());
113-
let sysroot = openat::Dir::open("/")?;
114-
let mut state_guard =
115-
SavedState::acquire_write_lock(sysroot).context("Failed to acquire write lock")?;
113+
let mut state_guard = SavedState::acquire_write_lock(openat::Dir::open("/")?)
114+
.context("Failed to acquire write lock")?;
116115
state_guard
117116
.update_state(&state)
118117
.context("Failed to update state")?;
119118

120119
let newinst = component
121-
.run_update(&inst)
120+
.run_update(&state_guard.sysroot, &inst)
122121
.with_context(|| format!("Failed to update {}", component.name()))?;
123122
state.installed.insert(component.name().into(), newinst);
124123
pending_container.remove(component.name());

src/component.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ pub(crate) trait Component {
5252
fn query_update(&self) -> Result<Option<ContentMetadata>>;
5353

5454
/// Used on the client to run an update.
55-
fn run_update(&self, current: &InstalledContent) -> Result<InstalledContent>;
55+
fn run_update(
56+
&self,
57+
sysroot: &openat::Dir,
58+
current: &InstalledContent,
59+
) -> Result<InstalledContent>;
5660

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

74+
/// Returns the path to the payload directory for an available update for
75+
/// a component.
76+
pub(crate) fn component_updatedirname(component: &dyn Component) -> PathBuf {
77+
Path::new(BOOTUPD_UPDATES_DIR).join(component.name())
78+
}
79+
7080
/// Returns the path to the payload directory for an available update for
7181
/// a component.
7282
pub(crate) fn component_updatedir(sysroot: &str, component: &dyn Component) -> PathBuf {
73-
Path::new(sysroot)
74-
.join(BOOTUPD_UPDATES_DIR)
75-
.join(component.name())
83+
Path::new(sysroot).join(component_updatedirname(component))
7684
}
7785

7886
/// Returns the name of the JSON file containing a component's available update metadata installed

src/efi.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,19 @@ impl Component for EFI {
128128
})
129129
}
130130

131-
fn run_update(&self, current: &InstalledContent) -> Result<InstalledContent> {
131+
fn run_update(
132+
&self,
133+
sysroot: &openat::Dir,
134+
current: &InstalledContent,
135+
) -> Result<InstalledContent> {
132136
let currentf = current
133137
.filetree
134138
.as_ref()
135139
.ok_or_else(|| anyhow::anyhow!("No filetree for installed EFI found!"))?;
136140
let updatemeta = self.query_update()?.expect("update available");
137-
let updated =
138-
openat::Dir::open(&component_updatedir("/", self)).context("opening update dir")?;
141+
let updated = sysroot
142+
.sub_dir(&component_updatedirname(self))
143+
.context("opening update dir")?;
139144
let updatef = filetree::FileTree::new_from_dir(&updated).context("reading update dir")?;
140145
let diff = currentf.diff(&updatef)?;
141146
let destdir = openat::Dir::open(&Path::new("/").join(MOUNT_PATH).join("EFI"))

0 commit comments

Comments
 (0)