@@ -79,11 +79,27 @@ impl Efi {
7979 // Get mounted point for esp
8080 pub ( crate ) fn get_mounted_esp ( & self , root : & Path ) -> Result < Option < PathBuf > > {
8181 // First check all potential mount points without holding the borrow
82- let found_mount = ESP_MOUNTS . iter ( ) . map ( |& mnt| root. join ( mnt) ) . find ( |mnt| {
83- mnt. exists ( )
84- && rustix:: fs:: statfs ( mnt) . map_or ( false , |st| st. f_type == libc:: MSDOS_SUPER_MAGIC )
85- && util:: ensure_writable_mount ( mnt) . is_ok ( )
86- } ) ;
82+ let found_mount =
83+ ESP_MOUNTS
84+ . iter ( )
85+ . try_fold ( None , |mntpoint, & mnt| -> anyhow:: Result < _ > {
86+ // return for the first match
87+ if mntpoint. is_some ( ) {
88+ return Ok ( mntpoint) ;
89+ }
90+ let path = root. join ( mnt) ;
91+ if !path. exists ( ) {
92+ return Ok ( None ) ;
93+ }
94+
95+ let st = rustix:: fs:: statfs ( & path) ?;
96+ if st. f_type == libc:: MSDOS_SUPER_MAGIC {
97+ util:: ensure_writable_mount ( & path) ?;
98+ Ok ( Some ( path) )
99+ } else {
100+ Ok ( None )
101+ }
102+ } ) ?;
87103
88104 // Only borrow mutably if we found a mount point
89105 if let Some ( mnt) = found_mount {
@@ -266,8 +282,7 @@ impl Component for Efi {
266282 anyhow:: bail!( "Failed to find adoptable system" )
267283 } ;
268284
269- // Confirm that esp_devices is Some(value)
270- let esp_devices = esp_devices. unwrap ( ) ;
285+ let esp_devices = esp_devices. unwrap_or_default ( ) ;
271286 let mut devices = esp_devices. iter ( ) ;
272287 let Some ( esp) = devices. next ( ) else {
273288 anyhow:: bail!( "Failed to find esp device" ) ;
@@ -445,8 +460,7 @@ impl Component for Efi {
445460 . as_ref ( )
446461 . ok_or_else ( || anyhow:: anyhow!( "No filetree for installed EFI found!" ) ) ?;
447462
448- // Confirm that esp_devices is Some(value)
449- let esp_devices = esp_devices. unwrap ( ) ;
463+ let esp_devices = esp_devices. unwrap_or_default ( ) ;
450464 let mut devices = esp_devices. iter ( ) ;
451465 let Some ( esp) = devices. next ( ) else {
452466 anyhow:: bail!( "Failed to find esp device" ) ;
0 commit comments