Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 26046df

Browse files
committed
efi: Fix the failed validation if installing from usr/lib/efi
1 parent 35a7faa commit 26046df

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/efi.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
use std::cell::RefCell;
8+
use std::collections::BTreeMap;
89
use std::os::unix::io::AsRawFd;
910
use std::path::{Path, PathBuf};
1011
use std::process::Command;
@@ -580,14 +581,26 @@ impl Component for Efi {
580581
.as_ref()
581582
.ok_or_else(|| anyhow::anyhow!("No filetree for installed EFI found!"))?;
582583

584+
// Remove EFI prefix of the current filetree children path
585+
// "shim/<ver>/EFI/fedora/shim.efi" -> "fedora/shim.efi"
586+
let mut prune_children = BTreeMap::new();
587+
for (pathstr, info) in currentf.children.iter() {
588+
let path = Utf8Path::new(pathstr);
589+
let prune_path = filetree::get_dest_efi_path(path).to_string();
590+
prune_children.insert(prune_path, info.to_owned());
591+
}
592+
let curentf_prune = filetree::FileTree {
593+
children: prune_children,
594+
};
595+
583596
let mut errs = Vec::new();
584597
let esp_devices = esp_devices.unwrap_or_default();
585598
for esp in esp_devices.iter() {
586599
let destpath = &self.ensure_mounted_esp(Path::new("/"), Path::new(&esp))?;
587600

588601
let efidir = openat::Dir::open(&destpath.join("EFI"))
589602
.with_context(|| format!("opening EFI dir {}", destpath.display()))?;
590-
let diff = currentf.relative_diff_to(&efidir)?;
603+
let diff = curentf_prune.relative_diff_to(&efidir)?;
591604

592605
for f in diff.changes.iter() {
593606
errs.push(format!("Changed: {}", f));

src/filetree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ fn get_first_dir(path: &Utf8Path) -> Result<(Utf8PathBuf, String)> {
406406
target_arch = "aarch64",
407407
target_arch = "riscv64"
408408
))]
409-
fn get_dest_efi_path(path: &Utf8Path) -> Utf8PathBuf {
409+
pub(crate) fn get_dest_efi_path(path: &Utf8Path) -> Utf8PathBuf {
410410
let parts: Vec<_> = path.iter().collect();
411411
if parts.get(2).map(|c| *c == "EFI").unwrap_or(false) {
412412
return parts.iter().skip(3).collect();

0 commit comments

Comments
 (0)