File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -330,6 +330,17 @@ pub fn remove(files: &[&OsStr], options: &Options) -> bool {
330330 had_err
331331}
332332
333+ /// Whether the given directory is empty.
334+ ///
335+ /// `path` must be a directory. If there is an error reading the
336+ /// contents of the directory, this returns `false`.
337+ fn is_dir_empty ( path : & Path ) -> bool {
338+ match std:: fs:: read_dir ( path) {
339+ Err ( _) => false ,
340+ Ok ( iter) => iter. count ( ) == 0 ,
341+ }
342+ }
343+
333344/// Whether the given file or directory is writable.
334345#[ cfg( unix) ]
335346fn is_writable ( path : & Path ) -> bool {
@@ -403,7 +414,7 @@ fn handle_dir(path: &Path, options: &Options) -> bool {
403414 if file_type. is_dir ( ) {
404415 // If we are in Interactive Mode Always and the directory isn't empty we ask if we should descend else we push this directory onto dirs vector
405416 if options. interactive == InteractiveMode :: Always
406- && fs :: read_dir ( entry. path ( ) ) . unwrap ( ) . count ( ) != 0
417+ && ! is_dir_empty ( entry. path ( ) )
407418 {
408419 // If we don't descend we push this directory onto our not_descended vector else we push this directory onto dirs vector
409420 if prompt_descend ( entry. path ( ) ) {
You can’t perform that action at this time.
0 commit comments