Browse Source

Kernel: Count remaining children in VirtualFileSystem::rmdir() manually

To count the remaining children, we simply need to traverse the
directory and increment a counter. No need for a custom virtual that
all file systems have to implement. :^)
Andreas Kling 4 years ago
parent
commit
d1bbe8b652
1 changed files with 8 additions and 4 deletions
  1. 8 4
      Kernel/FileSystem/VirtualFileSystem.cpp

+ 8 - 4
Kernel/FileSystem/VirtualFileSystem.cpp

@@ -747,11 +747,15 @@ KResult VirtualFileSystem::rmdir(StringView path, Custody& base)
             return EACCES;
             return EACCES;
     }
     }
 
 
-    KResultOr<size_t> dir_count_result = inode.directory_entry_count();
-    if (dir_count_result.is_error())
-        return dir_count_result.result();
+    size_t child_count = 0;
+    auto traversal_result = inode.traverse_as_directory([&child_count](auto&) {
+        ++child_count;
+        return true;
+    });
+    if (traversal_result.is_error())
+        return traversal_result;
 
 
-    if (dir_count_result.value() != 2)
+    if (child_count != 2)
         return ENOTEMPTY;
         return ENOTEMPTY;
 
 
     if (custody.is_readonly())
     if (custody.is_readonly())