Просмотр исходного кода

fix: Add windows implementation of is_empty_dir

Robert Minsk 2 лет назад
Родитель
Сommit
fc9f3ba089
1 измененных файлов с 21 добавлено и 8 удалено
  1. 21 8
      src/fs/file.rs

+ 21 - 8
src/fs/file.rs

@@ -428,9 +428,6 @@ impl<'dir> File<'dir> {
     }
 
     // To display icons for empty folders.
-    // The naive approach, as one would think that this info may have been cached.
-    // but as mentioned in the size function comment above, different filesystems
-    // make it difficult to get any info about a dir by it's size, so this may be it.
     #[cfg(unix)]
     pub fn is_empty_dir(&self) -> bool {
         if self.is_directory() {
@@ -442,17 +439,33 @@ impl<'dir> File<'dir> {
                 // has subdirectories.
                 false
             } else {
-                match Dir::read_dir(self.path.clone()) {
-                    // . & .. are skipped, if the returned iterator has .next(), it's not empty
-                    Ok(has_files) => has_files.files(super::DotFilter::Dotfiles, None, false, false).next().is_none(),
-                    Err(_) => false,
-                }
+                self.is_empty_directory()
             }
         } else {
             false
         }
     }
 
+    #[cfg(windows)]
+    pub fn is_empty_dir(&self) -> bool {
+        if self.is_directory() {
+            self.is_empty_directory()
+        } else {
+            false
+        }
+    }
+
+    // The naive approach, as one would think that this info may have been cached.
+    // but as mentioned in the size function comment above, different filesystems
+    // make it difficult to get any info about a dir by it's size, so this may be it.
+    fn is_empty_directory(&self) -> bool {
+        match Dir::read_dir(self.path.clone()) {
+            // . & .. are skipped, if the returned iterator has .next(), it's not empty
+            Ok(has_files) => has_files.files(super::DotFilter::Dotfiles, None, false, false).next().is_none(),
+            Err(_) => false,
+        }
+    }
+
     #[cfg(windows)]
     pub fn size(&self) -> f::Size {
         if self.is_directory() {