1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:28:12 +00:00

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. :^)
This commit is contained in:
Andreas Kling 2021-07-17 22:34:43 +02:00
parent a3f58a5003
commit d1bbe8b652

View file

@ -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(); size_t child_count = 0;
if (dir_count_result.is_error()) auto traversal_result = inode.traverse_as_directory([&child_count](auto&) {
return dir_count_result.result(); ++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())