Skip to content

Commit 365ef1f

Browse files
component: Make update metadata generation to be optional
Currently, the `bootupctl backend generate-update-metadata` command tries to generate an update layout for each component, and it bails out if one of the components can't be installed. There are systems in which some of the bootupd components are not needed (e.g.: x86_64 EFI-only systems). But if one of the requirements for one of the components is not meet (e.g.: grub2-install is missing for BIOS), this will lead to a fatal error instead of just skipping the component that is not supported. To prevent this, let's make the update layout generation to be optional. Signed-off-by: Javier Martinez Canillas <[email protected]>
1 parent de779db commit 365ef1f

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

src/bios.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl Component for Bios {
127127
})
128128
}
129129

130-
fn generate_update_metadata(&self, sysroot_path: &str) -> Result<ContentMetadata> {
130+
fn generate_update_metadata(&self, sysroot_path: &str) -> Result<Option<ContentMetadata>> {
131131
let grub_install = Path::new(sysroot_path).join(GRUB_BIN);
132132
if !grub_install.exists() {
133133
bail!("Failed to find {:?}", grub_install);
@@ -136,7 +136,7 @@ impl Component for Bios {
136136
// Query the rpm database and list the package and build times for /usr/sbin/grub2-install
137137
let meta = packagesystem::query_files(sysroot_path, [&grub_install])?;
138138
write_update_metadata(sysroot_path, self, &meta)?;
139-
Ok(meta)
139+
Ok(Some(meta))
140140
}
141141

142142
fn query_adopt(&self, devices: &Option<Vec<String>>) -> Result<Option<Adoptable>> {

src/bootupd.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,18 @@ pub(crate) fn generate_update_metadata(sysroot_path: &str) -> Result<()> {
199199
std::fs::create_dir_all(&updates_dir)
200200
.with_context(|| format!("Failed to create updates dir {:?}", &updates_dir))?;
201201
for component in get_components().values() {
202-
let v = component.generate_update_metadata(sysroot_path)?;
203-
println!(
204-
"Generated update layout for {}: {}",
205-
component.name(),
206-
v.version,
207-
);
202+
if let Some(v) = component.generate_update_metadata(sysroot_path)? {
203+
println!(
204+
"Generated update layout for {}: {}",
205+
component.name(),
206+
v.version,
207+
);
208+
} else {
209+
println!(
210+
"Generating update layout for {} was not possible, skipping.",
211+
component.name(),
212+
);
213+
}
208214
}
209215

210216
Ok(())

src/component.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub(crate) trait Component {
6262
/// this is an `rpm-ostree compose tree` for example. For a dual-partition
6363
/// style updater, this would be run as part of a postprocessing step
6464
/// while the filesystem for the partition is mounted.
65-
fn generate_update_metadata(&self, sysroot: &str) -> Result<ContentMetadata>;
65+
fn generate_update_metadata(&self, sysroot: &str) -> Result<Option<ContentMetadata>>;
6666

6767
/// Used on the client to query for an update cached in the current booted OS.
6868
fn query_update(&self, sysroot: &openat::Dir) -> Result<Option<ContentMetadata>>;

src/efi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ impl Component for Efi {
460460
})
461461
}
462462

463-
fn generate_update_metadata(&self, sysroot: &str) -> Result<ContentMetadata> {
463+
fn generate_update_metadata(&self, sysroot: &str) -> Result<Option<ContentMetadata>> {
464464
let sysroot_path = Utf8Path::new(sysroot);
465465

466466
// copy EFI files to updates dir from usr/lib/efi
@@ -533,7 +533,7 @@ impl Component for Efi {
533533
};
534534

535535
write_update_metadata(sysroot, self, &meta)?;
536-
Ok(meta)
536+
Ok(Some(meta))
537537
}
538538

539539
fn query_update(&self, sysroot: &openat::Dir) -> Result<Option<ContentMetadata>> {

0 commit comments

Comments
 (0)