@@ -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