@@ -366,7 +366,7 @@ pub(crate) fn copy_dir(root: &openat::Dir, src: &str, dst: &str) -> Result<()> {
366
366
target_arch = "aarch64" ,
367
367
target_arch = "riscv64"
368
368
) ) ]
369
- fn get_first_dir ( path : & Utf8Path ) -> Result < ( & Utf8Path , String ) > {
369
+ fn get_first_dir ( path : & Utf8Path ) -> Result < ( Utf8PathBuf , String ) > {
370
370
let first = path
371
371
. iter ( )
372
372
. next ( )
@@ -376,6 +376,15 @@ fn get_first_dir(path: &Utf8Path) -> Result<(&Utf8Path, String)> {
376
376
Ok ( ( first. into ( ) , tmp) )
377
377
}
378
378
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
+
379
388
/// Given two directories, apply a diff generated from srcdir to destdir
380
389
#[ cfg( any(
381
390
target_arch = "x86_64" ,
@@ -398,8 +407,8 @@ pub(crate) fn apply_diff(
398
407
// Handle removals in temp dir, or remove directly if file not in dir
399
408
if !opts. skip_removals {
400
409
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) ?;
403
412
let path_tmp;
404
413
if first_dir != path {
405
414
path_tmp = Utf8Path :: new ( & first_dir_tmp) . join ( path. strip_prefix ( & first_dir) ?) ;
@@ -421,8 +430,9 @@ pub(crate) fn apply_diff(
421
430
}
422
431
// Write changed or new files to temp dir or temp file
423
432
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) ?;
426
436
let mut path_tmp = Utf8PathBuf :: from ( & first_dir_tmp) ;
427
437
if first_dir != path {
428
438
if !destdir. exists ( & first_dir_tmp) ? && destdir. exists ( first_dir. as_std_path ( ) ) ? {
@@ -443,7 +453,7 @@ pub(crate) fn apply_diff(
443
453
}
444
454
updates. insert ( first_dir, first_dir_tmp) ;
445
455
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 ( ) )
447
457
. with_context ( || format ! ( "copying {:?} to {:?}" , path, path_tmp) ) ?;
448
458
}
449
459
0 commit comments