From d1bbe8b65220ab500917aaf79d2051023fb00ec6 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 17 Jul 2021 22:34:43 +0200 Subject: [PATCH] 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. :^) --- Kernel/FileSystem/VirtualFileSystem.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index dea72217e5..455db3723d 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -747,11 +747,15 @@ KResult VirtualFileSystem::rmdir(StringView path, Custody& base) return EACCES; } - KResultOr 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; if (custody.is_readonly())