Skip to content

Commit d178c25

Browse files
committed
efi: Extend update() to support usr/lib/efi
1 parent 8d4fed9 commit d178c25

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

src/efi.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,22 @@ impl Component for Efi {
319319
return Ok(None);
320320
};
321321

322+
let efilib_path = rootcxt.path.join(EFILIB);
323+
let efi_comps = if efilib_path.exists() {
324+
get_efi_component_from_usr(&rootcxt.path, EFILIB)?
325+
} else {
326+
None
327+
};
328+
329+
let updated_path = if efi_comps.is_some() {
330+
PathBuf::from(EFILIB)
331+
} else {
332+
component_updatedirname(self)
333+
};
334+
322335
let updated = rootcxt
323336
.sysroot
324-
.sub_dir(&component_updatedirname(self))
337+
.sub_dir(&updated_path)
325338
.context("opening update dir")?;
326339
let updatef = filetree::FileTree::new_from_dir(&updated).context("reading update dir")?;
327340

@@ -448,8 +461,22 @@ impl Component for Efi {
448461
.ok_or_else(|| anyhow::anyhow!("No filetree for installed EFI found!"))?;
449462
let sysroot_dir = &rootcxt.sysroot;
450463
let updatemeta = self.query_update(sysroot_dir)?.expect("update available");
464+
465+
let efilib_path = rootcxt.path.join(EFILIB);
466+
let efi_comps = if efilib_path.exists() {
467+
get_efi_component_from_usr(&rootcxt.path, EFILIB)?
468+
} else {
469+
None
470+
};
471+
472+
let updated_path = if efi_comps.is_some() {
473+
PathBuf::from(EFILIB)
474+
} else {
475+
component_updatedirname(self)
476+
};
477+
451478
let updated = sysroot_dir
452-
.sub_dir(&component_updatedirname(self))
479+
.sub_dir(&updated_path)
453480
.context("opening update dir")?;
454481
let updatef = filetree::FileTree::new_from_dir(&updated).context("reading update dir")?;
455482
let diff = currentf.diff(&updatef)?;

src/filetree.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ pub(crate) fn copy_dir(root: &openat::Dir, src: &str, dst: &str) -> Result<()> {
366366
target_arch = "aarch64",
367367
target_arch = "riscv64"
368368
))]
369-
fn get_first_dir(path: &Utf8Path) -> Result<(&Utf8Path, String)> {
369+
fn get_first_dir(path: &Utf8Path) -> Result<(Utf8PathBuf, String)> {
370370
let first = path
371371
.iter()
372372
.next()
@@ -376,6 +376,15 @@ fn get_first_dir(path: &Utf8Path) -> Result<(&Utf8Path, String)> {
376376
Ok((first.into(), tmp))
377377
}
378378

379+
/// Get dest efi path "shim/<ver>/EFI/fedora/shim.efi" -> "fedora/shim.efi"
380+
fn get_dest_efi_path(path: &Utf8Path) -> Utf8PathBuf {
381+
let parts: Vec<_> = path.iter().collect();
382+
if parts.get(2).map(|c| *c == "EFI").unwrap_or(false) {
383+
return parts.iter().skip(3).collect();
384+
}
385+
path.to_path_buf()
386+
}
387+
379388
/// Given two directories, apply a diff generated from srcdir to destdir
380389
#[cfg(any(
381390
target_arch = "x86_64",
@@ -398,8 +407,8 @@ pub(crate) fn apply_diff(
398407
// Handle removals in temp dir, or remove directly if file not in dir
399408
if !opts.skip_removals {
400409
for pathstr in diff.removals.iter() {
401-
let path = Utf8Path::new(pathstr);
402-
let (first_dir, first_dir_tmp) = get_first_dir(path)?;
410+
let path = get_dest_efi_path(Utf8Path::new(pathstr));
411+
let (first_dir, first_dir_tmp) = get_first_dir(&path)?;
403412
let path_tmp;
404413
if first_dir != path {
405414
path_tmp = Utf8Path::new(&first_dir_tmp).join(path.strip_prefix(&first_dir)?);
@@ -421,8 +430,9 @@ pub(crate) fn apply_diff(
421430
}
422431
// Write changed or new files to temp dir or temp file
423432
for pathstr in diff.changes.iter().chain(diff.additions.iter()) {
424-
let path = Utf8Path::new(pathstr);
425-
let (first_dir, first_dir_tmp) = get_first_dir(path)?;
433+
let src_path = Utf8Path::new(pathstr);
434+
let path = get_dest_efi_path(src_path);
435+
let (first_dir, first_dir_tmp) = get_first_dir(&path)?;
426436
let mut path_tmp = Utf8PathBuf::from(&first_dir_tmp);
427437
if first_dir != path {
428438
if !destdir.exists(&first_dir_tmp)? && destdir.exists(first_dir.as_std_path())? {
@@ -443,7 +453,7 @@ pub(crate) fn apply_diff(
443453
}
444454
updates.insert(first_dir, first_dir_tmp);
445455
srcdir
446-
.copy_file_at(path.as_std_path(), destdir, path_tmp.as_std_path())
456+
.copy_file_at(src_path.as_std_path(), destdir, path_tmp.as_std_path())
447457
.with_context(|| format!("copying {:?} to {:?}", path, path_tmp))?;
448458
}
449459

0 commit comments

Comments
 (0)