@@ -63,11 +63,13 @@ impl FileSystem {
6363 let mut src = self
6464 . open ( src_path, UefiFileMode :: Read , false ) ?
6565 . into_regular_file ( )
66- . ok_or ( Error :: Io ( IoError {
67- path : src_path. to_path_buf ( ) ,
68- context : IoErrorContext :: NotAFile ,
69- uefi_error : Status :: INVALID_PARAMETER . into ( ) ,
70- } ) ) ?;
66+ . ok_or_else ( || {
67+ Error :: Io ( IoError {
68+ path : src_path. to_path_buf ( ) ,
69+ context : IoErrorContext :: NotAFile ,
70+ uefi_error : Status :: INVALID_PARAMETER . into ( ) ,
71+ } )
72+ } ) ?;
7173
7274 // Get the source file's size in bytes.
7375 let src_size = {
@@ -91,11 +93,13 @@ impl FileSystem {
9193 let mut dest = self
9294 . open ( dest_path, UefiFileMode :: CreateReadWrite , false ) ?
9395 . into_regular_file ( )
94- . ok_or ( Error :: Io ( IoError {
95- path : dest_path. to_path_buf ( ) ,
96- context : IoErrorContext :: OpenError ,
97- uefi_error : Status :: INVALID_PARAMETER . into ( ) ,
98- } ) ) ?;
96+ . ok_or_else ( || {
97+ Error :: Io ( IoError {
98+ path : dest_path. to_path_buf ( ) ,
99+ context : IoErrorContext :: OpenError ,
100+ uefi_error : Status :: INVALID_PARAMETER . into ( ) ,
101+ } )
102+ } ) ?;
99103
100104 // 1 MiB copy buffer.
101105 let mut chunk = vec ! [ 0 ; 1024 * 1024 ] ;
@@ -198,13 +202,15 @@ impl FileSystem {
198202 let mut file = self
199203 . open ( path, UefiFileMode :: Read , false ) ?
200204 . into_regular_file ( )
201- . ok_or ( Error :: Io ( IoError {
202- path : path. to_path_buf ( ) ,
203- context : IoErrorContext :: NotAFile ,
204- // We do not have a real UEFI error here as we have a logical
205- // problem.
206- uefi_error : Status :: INVALID_PARAMETER . into ( ) ,
207- } ) ) ?;
205+ . ok_or_else ( || {
206+ Error :: Io ( IoError {
207+ path : path. to_path_buf ( ) ,
208+ context : IoErrorContext :: NotAFile ,
209+ // We do not have a real UEFI error here as we have a logical
210+ // problem.
211+ uefi_error : Status :: INVALID_PARAMETER . into ( ) ,
212+ } )
213+ } ) ?;
208214
209215 let info = file. get_boxed_info :: < UefiFileInfo > ( ) . map_err ( |err| {
210216 Error :: Io ( IoError {
@@ -237,13 +243,15 @@ impl FileSystem {
237243 let dir = self
238244 . open ( path, UefiFileMode :: Read , false ) ?
239245 . into_directory ( )
240- . ok_or ( Error :: Io ( IoError {
241- path : path. to_path_buf ( ) ,
242- context : IoErrorContext :: NotADirectory ,
243- // We do not have a real UEFI error here as we have a logical
244- // problem.
245- uefi_error : Status :: INVALID_PARAMETER . into ( ) ,
246- } ) ) ?;
246+ . ok_or_else ( || {
247+ Error :: Io ( IoError {
248+ path : path. to_path_buf ( ) ,
249+ context : IoErrorContext :: NotADirectory ,
250+ // We do not have a real UEFI error here as we have a logical
251+ // problem.
252+ uefi_error : Status :: INVALID_PARAMETER . into ( ) ,
253+ } )
254+ } ) ?;
247255 Ok ( UefiDirectoryIter :: new ( dir) )
248256 }
249257
0 commit comments