Skip to content

Commit caf0187

Browse files
committed
filetree: Get correct dest efi path "shim/<ver>/EFI/fedora/shim.efi"
-> "fedora/shim.efi"
1 parent d57fbdf commit caf0187

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/filetree.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,15 @@ fn get_first_dir(path: &Utf8Path) -> Result<(Utf8PathBuf, String)> {
395395
Ok((first.into(), tmp))
396396
}
397397

398+
/// Get dest efi path "shim/<ver>/EFI/fedora/shim.efi" -> "fedora/shim.efi"
399+
fn get_dest_efi_path(path: &Utf8Path) -> Utf8PathBuf {
400+
let parts: Vec<_> = path.iter().collect();
401+
if parts.get(2).map(|c| *c == "EFI").unwrap_or(false) {
402+
return parts.iter().skip(3).collect();
403+
}
404+
path.to_path_buf()
405+
}
406+
398407
/// Given two directories, apply a diff generated from srcdir to destdir
399408
#[cfg(any(
400409
target_arch = "x86_64",
@@ -417,8 +426,8 @@ pub(crate) fn apply_diff(
417426
// Handle removals in temp dir, or remove directly if file not in dir
418427
if !opts.skip_removals {
419428
for pathstr in diff.removals.iter() {
420-
let path = Utf8Path::new(pathstr);
421-
let (first_dir, first_dir_tmp) = get_first_dir(path)?;
429+
let path = get_dest_efi_path(Utf8Path::new(pathstr));
430+
let (first_dir, first_dir_tmp) = get_first_dir(&path)?;
422431
let path_tmp;
423432
if first_dir != path {
424433
path_tmp = Utf8Path::new(&first_dir_tmp).join(path.strip_prefix(&first_dir)?);
@@ -440,8 +449,9 @@ pub(crate) fn apply_diff(
440449
}
441450
// Write changed or new files to temp dir or temp file
442451
for pathstr in diff.changes.iter().chain(diff.additions.iter()) {
443-
let path = Utf8Path::new(pathstr);
444-
let (first_dir, first_dir_tmp) = get_first_dir(path)?;
452+
let src_path = Utf8Path::new(pathstr);
453+
let path = get_dest_efi_path(src_path);
454+
let (first_dir, first_dir_tmp) = get_first_dir(&path)?;
445455
let mut path_tmp = Utf8PathBuf::from(&first_dir_tmp);
446456
if first_dir != path {
447457
if !destdir.exists(&first_dir_tmp)? && destdir.exists(first_dir.as_std_path())? {
@@ -462,7 +472,7 @@ pub(crate) fn apply_diff(
462472
}
463473
updates.insert(first_dir, first_dir_tmp);
464474
srcdir
465-
.copy_file_at(path.as_std_path(), destdir, path_tmp.as_std_path())
475+
.copy_file_at(src_path.as_std_path(), destdir, path_tmp.as_std_path())
466476
.with_context(|| format!("copying {:?} to {:?}", path, path_tmp))?;
467477
}
468478

0 commit comments

Comments
 (0)