Skip to content

Commit 56eb7d6

Browse files
committed
efi: update get_efi_component_from_usr() to return Option
1 parent 5a6bba3 commit 56eb7d6

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/efi.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -453,16 +453,18 @@ impl Component for Efi {
453453
fn generate_update_metadata(&self, sysroot: &str) -> Result<ContentMetadata> {
454454
let sysroot_path = Utf8Path::new(sysroot);
455455

456-
// copy EFI files to updates dir from usr/lib/efi
457456
let efilib_path = sysroot_path.join(EFILIB);
458-
let meta = if efilib_path.exists() {
457+
let efi_comps = if efilib_path.exists() {
458+
get_efi_component_from_usr(&sysroot_path, EFILIB)?
459+
} else {
460+
None
461+
};
462+
463+
// copy EFI files to updates dir from usr/lib/efi
464+
let meta = if let Some(efi_components) = efi_comps {
459465
let mut packages = Vec::new();
460466
let mut modules_vec: Vec<Module> = vec![];
461467
let sysroot_dir = Dir::open_ambient_dir(sysroot_path, cap_std::ambient_authority())?;
462-
let efi_components = get_efi_component_from_usr(&sysroot_path, EFILIB)?;
463-
if efi_components.len() == 0 {
464-
bail!("Failed to find EFI components from {efilib_path}");
465-
}
466468
for efi in efi_components {
467469
Command::new("cp")
468470
.args(["-rp", "--reflink=auto"])
@@ -734,7 +736,7 @@ pub struct EFIComponent {
734736
fn get_efi_component_from_usr<'a>(
735737
sysroot: &'a Utf8Path,
736738
usr_path: &'a str,
737-
) -> Result<Vec<EFIComponent>> {
739+
) -> Result<Option<Vec<EFIComponent>>> {
738740
let efilib_path = sysroot.join(usr_path);
739741
let skip_count = Utf8Path::new(usr_path).components().count();
740742

@@ -765,9 +767,12 @@ fn get_efi_component_from_usr<'a>(
765767
})
766768
.collect();
767769

770+
if components.len() == 0 {
771+
return Ok(None);
772+
}
768773
components.sort_by(|a, b| a.name.cmp(&b.name));
769774

770-
Ok(components)
775+
Ok(Some(components))
771776
}
772777

773778
#[cfg(test)]
@@ -904,7 +909,7 @@ Boot0003* test";
904909
let efi_comps = get_efi_component_from_usr(utf8_tpath, EFILIB)?;
905910
assert_eq!(
906911
efi_comps,
907-
vec![
912+
Some(vec![
908913
EFIComponent {
909914
name: "BAR".to_string(),
910915
version: "1.1".to_string(),
@@ -915,12 +920,12 @@ Boot0003* test";
915920
version: "1.1".to_string(),
916921
path: Utf8PathBuf::from("usr/lib/efi/FOO/1.1/EFI"),
917922
},
918-
]
923+
])
919924
);
920925
std::fs::remove_dir_all(efi_path.join("BAR/1.1/EFI"))?;
921926
std::fs::remove_dir_all(efi_path.join("FOO/1.1/EFI"))?;
922927
let efi_comps = get_efi_component_from_usr(utf8_tpath, EFILIB)?;
923-
assert_eq!(efi_comps, []);
928+
assert_eq!(efi_comps, None);
924929
Ok(())
925930
}
926931
}

0 commit comments

Comments
 (0)