@@ -21,10 +21,8 @@ use openat_ext::OpenatDirExt;
2121use os_release:: OsRelease ;
2222use rustix:: mount:: {
2323 fsconfig_create, fsconfig_set_path, fsmount, fsopen, move_mount, FsMountFlags , FsOpenFlags ,
24- MountAttrFlags , MoveMountFlags , UnmountFlags ,
24+ MoveMountFlags , MountAttrFlags , UnmountFlags ,
2525} ;
26- use rustix:: { fd:: AsFd , fd:: BorrowedFd , fs:: StatVfsMountFlags } ;
27- use walkdir:: WalkDir ;
2826use widestring:: U16CString ;
2927
3028use bootc_internal_blockdev:: Device ;
@@ -95,15 +93,10 @@ fn mount_esp(esp_device: &Path, target: &Path) -> Result<()> {
9593 use rustix:: fs:: CWD ;
9694
9795 let fs_fd = fsopen ( "vfat" , FsOpenFlags :: empty ( ) ) . context ( "fsopen vfat" ) ?;
98- fsconfig_set_path ( fs_fd. as_fd ( ) , "source" , esp_device, CWD )
99- . context ( "fsconfig_set_path source" ) ?;
96+ fsconfig_set_path ( fs_fd. as_fd ( ) , "source" , esp_device, CWD ) . context ( "fsconfig_set_path source" ) ?;
10097 fsconfig_create ( fs_fd. as_fd ( ) ) . context ( "fsconfig_create" ) ?;
101- let mount_fd = fsmount (
102- fs_fd. as_fd ( ) ,
103- FsMountFlags :: empty ( ) ,
104- MountAttrFlags :: empty ( ) ,
105- )
106- . context ( "fsmount" ) ?;
98+ let mount_fd =
99+ fsmount ( fs_fd. as_fd ( ) , FsMountFlags :: empty ( ) , MountAttrFlags :: empty ( ) ) . context ( "fsmount" ) ?;
107100 let target_dir = std:: fs:: File :: open ( target) . context ( "open target dir for move_mount" ) ?;
108101 let target_fd = unsafe { BorrowedFd :: borrow_raw ( target_dir. as_raw_fd ( ) ) } ;
109102 move_mount (
@@ -294,40 +287,32 @@ impl Efi {
294287 let device_path = device. path ( ) ;
295288 create_efi_boot_entry ( & device_path, esp_part_num. trim ( ) , & loader, & product_name)
296289 }
297- /// Copy EFI components to ESP using the same "write alongside + atomic rename" pattern
298- /// as bootable container updates, so the system stays bootable if any step fails.
299290 fn copy_efi_components_to_esp (
300291 & self ,
301292 sysroot_dir : & openat:: Dir ,
302293 esp_dir : & openat:: Dir ,
303- _esp_path : & Path ,
294+ esp_path : & Path ,
304295 efi_components : & [ EFIComponent ] ,
305296 ) -> Result < ( ) > {
306- // Build a merged source tree in a temp dir (same layout as desired ESP/EFI)
307- let temp_dir = tempfile:: tempdir ( ) . context ( "Creating temp dir for EFI merge" ) ?;
308- let temp_efi_path = temp_dir. path ( ) . join ( "EFI" ) ;
309- std:: fs:: create_dir_all ( & temp_efi_path)
310- . with_context ( || format ! ( "Creating {}" , temp_efi_path. display( ) ) ) ?;
311- let temp_efi_str = temp_efi_path
297+ let dest_str = esp_path
312298 . to_str ( )
313- . context ( "Temp EFI path is not valid UTF-8" ) ?;
299+ . with_context ( || format ! ( "Invalid UTF-8: {}" , esp_path . display ( ) ) ) ?;
314300
315301 for efi_comp in efi_components {
316302 log:: info!(
317- "Merging EFI component {} version {} into update tree " ,
303+ "Copying EFI component {} version {} to ESP at {} " ,
318304 efi_comp. name,
319- efi_comp. version
305+ efi_comp. version,
306+ esp_path. display( )
320307 ) ;
321- // Copy contents of component's EFI dir (e.g. fedora/) into temp_efi_path so merged
322- // layout is EFI/fedora/..., not EFI/EFI/fedora/...
323- let src_efi_contents = format ! ( "{}/." , efi_comp. path) ;
324- filetree:: copy_dir_with_args (
325- sysroot_dir,
326- src_efi_contents. as_str ( ) ,
327- temp_efi_str,
328- OPTIONS ,
329- )
330- . with_context ( || format ! ( "Copying {} to merge dir" , efi_comp. path) ) ?;
308+
309+ filetree:: copy_dir_with_args ( sysroot_dir, efi_comp. path . as_str ( ) , dest_str, OPTIONS )
310+ . with_context ( || {
311+ format ! (
312+ "Failed to copy {} from {} to {}" ,
313+ efi_comp. name, efi_comp. path, dest_str
314+ )
315+ } ) ?;
331316 }
332317
333318 // Ensure ESP/EFI exists (e.g. first install)
@@ -370,7 +355,6 @@ impl Efi {
370355 fn package_mode_copy_to_boot_impl ( & self , sysroot : & Path ) -> Result < ( ) > {
371356 let sysroot_path = Utf8Path :: from_path ( sysroot)
372357 . with_context ( || format ! ( "Invalid UTF-8: {}" , sysroot. display( ) ) ) ?;
373- let sysroot_dir = openat:: Dir :: open ( sysroot) . context ( "Opening sysroot for reading" ) ?;
374358
375359 let efi_comps = match get_efi_component_from_usr ( sysroot_path, EFILIB ) ? {
376360 Some ( comps) if !comps. is_empty ( ) => comps,
@@ -398,6 +382,7 @@ impl Efi {
398382 . with_context ( || format ! ( "Opening ESP at {}" , esp_path. display( ) ) ) ?;
399383 validate_esp_fstype ( & esp_dir) ?;
400384
385+ let sysroot_dir = openat:: Dir :: open ( sysroot) . context ( "Opening sysroot for reading" ) ?;
401386 self . copy_efi_components_to_esp ( & sysroot_dir, & esp_dir, & esp_path, & efi_comps) ?;
402387
403388 log:: info!(
0 commit comments