@@ -349,8 +349,6 @@ impl Component for Efi {
349349 anyhow:: bail!( "No update metadata for component {} found" , self . name( ) ) ;
350350 } ;
351351 log:: debug!( "Found metadata {}" , meta. version) ;
352- let srcdir_name = component_updatedirname ( self ) ;
353- let ft = crate :: filetree:: FileTree :: new_from_dir ( & src_dir. sub_dir ( & srcdir_name) ?) ?;
354352
355353 // Let's attempt to use an already mounted ESP at the target
356354 // dest_root if one is already mounted there in a known ESP location.
@@ -371,16 +369,35 @@ impl Component for Efi {
371369 . with_context ( || format ! ( "opening dest dir {}" , destpath. display( ) ) ) ?;
372370 validate_esp_fstype ( destd) ?;
373371
374- // TODO - add some sort of API that allows directly setting the working
375- // directory to a file descriptor.
376- std:: process:: Command :: new ( "cp" )
377- . args ( [ "-rp" , "--reflink=auto" ] )
378- . arg ( & srcdir_name)
379- . arg ( destpath)
380- . current_dir ( format ! ( "/proc/self/fd/{}" , src_dir. as_raw_fd( ) ) )
381- . run ( ) ?;
372+ let sysroot_path = Utf8Path :: new ( src_root) ;
373+ let efilib_path = sysroot_path. join ( EFILIB ) ;
374+ let efi_comps = if efilib_path. exists ( ) {
375+ get_efi_component_from_usr ( & sysroot_path, EFILIB ) ?
376+ } else {
377+ None
378+ } ;
379+
380+ let target_vendor_path;
381+
382+ // Copy EFI components from usr/lib/efi if existing
383+ let ft = if let Some ( efi_components) = efi_comps {
384+ target_vendor_path = efilib_path. to_string ( ) ;
385+ for efi in efi_components {
386+ log:: trace!( "Copy {} to {}" , efi. path, destpath. display( ) ) ;
387+ util:: copy_in_fd ( & src_dir, & efi. path . as_ref ( ) , destpath. as_path ( ) ) ?;
388+ }
389+ crate :: filetree:: FileTree :: new_from_dir ( & src_dir. sub_dir ( EFILIB ) ?) ?
390+ } else {
391+ let updatesdir_name = Utf8PathBuf :: from_path_buf ( component_updatedirname ( self ) )
392+ . expect ( "Invalide UTF-8 path" ) ;
393+ target_vendor_path = updatesdir_name. to_string ( ) ;
394+
395+ util:: copy_in_fd ( & src_dir, & target_vendor_path, destpath. as_path ( ) ) ?;
396+ crate :: filetree:: FileTree :: new_from_dir ( & src_dir. sub_dir ( & target_vendor_path) ?) ?
397+ } ;
398+
382399 if update_firmware {
383- if let Some ( vendordir) = self . get_efi_vendor ( & src_root ) ? {
400+ if let Some ( vendordir) = self . get_efi_vendor ( & target_vendor_path ) ? {
384401 self . update_firmware ( device, destd, & vendordir) ?
385402 }
386403 }
@@ -449,12 +466,11 @@ impl Component for Efi {
449466 let mut packages = Vec :: new ( ) ;
450467 let sysroot_dir = Dir :: open_ambient_dir ( sysroot_path, cap_std:: ambient_authority ( ) ) ?;
451468 for efi in efi_components {
452- Command :: new ( "cp" )
453- . args ( [ "-rp" , "--reflink=auto" ] )
454- . arg ( & efi. path )
455- . arg ( crate :: model:: BOOTUPD_UPDATES_DIR )
456- . current_dir ( format ! ( "/proc/self/fd/{}" , sysroot_dir. as_raw_fd( ) ) )
457- . run ( ) ?;
469+ util:: copy_in_fd (
470+ & sysroot_dir,
471+ & efi. path . as_ref ( ) ,
472+ crate :: model:: BOOTUPD_UPDATES_DIR ,
473+ ) ?;
458474 packages. push ( format ! ( "{}-{}" , efi. name, efi. version) ) ;
459475 }
460476
0 commit comments