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