@@ -395,6 +395,15 @@ fn get_first_dir(path: &Utf8Path) -> Result<(Utf8PathBuf, String)> {
395
395
Ok ( ( first. into ( ) , tmp) )
396
396
}
397
397
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
+
398
407
/// Given two directories, apply a diff generated from srcdir to destdir
399
408
#[ cfg( any(
400
409
target_arch = "x86_64" ,
@@ -417,8 +426,8 @@ pub(crate) fn apply_diff(
417
426
// Handle removals in temp dir, or remove directly if file not in dir
418
427
if !opts. skip_removals {
419
428
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) ?;
422
431
let path_tmp;
423
432
if first_dir != path {
424
433
path_tmp = Utf8Path :: new ( & first_dir_tmp) . join ( path. strip_prefix ( & first_dir) ?) ;
@@ -440,8 +449,9 @@ pub(crate) fn apply_diff(
440
449
}
441
450
// Write changed or new files to temp dir or temp file
442
451
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) ?;
445
455
let mut path_tmp = Utf8PathBuf :: from ( & first_dir_tmp) ;
446
456
if first_dir != path {
447
457
if !destdir. exists ( & first_dir_tmp) ? && destdir. exists ( first_dir. as_std_path ( ) ) ? {
@@ -462,7 +472,7 @@ pub(crate) fn apply_diff(
462
472
}
463
473
updates. insert ( first_dir, first_dir_tmp) ;
464
474
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 ( ) )
466
476
. with_context ( || format ! ( "copying {:?} to {:?}" , path, path_tmp) ) ?;
467
477
}
468
478
0 commit comments