@@ -11,6 +11,8 @@ use core::fmt;
11
11
use core:: fmt:: { Debug , Formatter } ;
12
12
use core:: ops:: Deref ;
13
13
use log:: debug;
14
+ use uefi:: CStr16 ;
15
+ use uefi_macros:: cstr16;
14
16
15
17
/// Return type for public [`FileSystem`] operations.
16
18
pub type FileSystemResult < T > = Result < T , Error > ;
@@ -181,11 +183,35 @@ impl<'a> FileSystem<'a> {
181
183
}
182
184
}
183
185
184
- /*/ // Removes a directory at this path, after removing all its contents. Use
186
+ /// Removes a directory at this path, after removing all its contents. Use
185
187
/// carefully!
186
188
pub fn remove_dir_all ( & mut self , path : impl AsRef < Path > ) -> FileSystemResult < ( ) > {
189
+ const SKIP_DIRS : [ & CStr16 ; 2 ] = [ cstr16 ! ( "." ) , cstr16 ! ( ".." ) ] ;
187
190
let path = path. as_ref ( ) ;
188
- }*/
191
+ for file_info in self
192
+ . read_dir ( path) ?
193
+ . filter_map ( |file_info_result| file_info_result. ok ( ) )
194
+ {
195
+ if SKIP_DIRS . contains ( & file_info. file_name ( ) ) {
196
+ continue ;
197
+ }
198
+
199
+ let mut abs_entry_path = PathBuf :: new ( ) ;
200
+ abs_entry_path. push ( path) ;
201
+ abs_entry_path. push ( file_info. file_name ( ) ) ;
202
+ if file_info. is_directory ( ) {
203
+ // delete all inner files
204
+ // This recursion is fine as there are no links in UEFI/FAT file
205
+ // systems. No cycles possible.
206
+ self . remove_dir_all ( & abs_entry_path) ?;
207
+ } else {
208
+ self . remove_file ( abs_entry_path) ?;
209
+ }
210
+ }
211
+ // Now that the dir is empty, we delete it as final step.
212
+ self . remove_dir ( path) ?;
213
+ Ok ( ( ) )
214
+ }
189
215
190
216
/// Removes a file from the filesystem.
191
217
pub fn remove_file ( & mut self , path : impl AsRef < Path > ) -> FileSystemResult < ( ) > {
@@ -282,17 +308,17 @@ impl<'a> FileSystem<'a> {
282
308
/// absolute path.
283
309
///
284
310
/// May create a file if [`UefiFileMode::CreateReadWrite`] is set. May
285
- /// create a directory if [`UefiFileMode::CreateReadWrite`] and `is_dir `
286
- /// is set.
311
+ /// create a directory if [`UefiFileMode::CreateReadWrite`] and `create_dir `
312
+ /// is set. The parameter `create_dir` is ignored otherwise.
287
313
fn open (
288
314
& mut self ,
289
315
path : & Path ,
290
316
mode : UefiFileMode ,
291
- is_dir : bool ,
317
+ create_dir : bool ,
292
318
) -> FileSystemResult < UefiFileHandle > {
293
319
validate_path ( path) ?;
294
320
295
- let attr = if mode == UefiFileMode :: CreateReadWrite && is_dir {
321
+ let attr = if mode == UefiFileMode :: CreateReadWrite && create_dir {
296
322
UefiFileAttribute :: DIRECTORY
297
323
} else {
298
324
UefiFileAttribute :: empty ( )
0 commit comments