mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 10:45:09 +00:00
Kernel: Make Inode::traverse_as_directory() callback return ErrorOr
This allows us to propagate errors from inside the callback with TRY().
This commit is contained in:
parent
a15ed8743d
commit
5ce753b74d
31 changed files with 154 additions and 151 deletions
|
@ -162,9 +162,9 @@ bool VirtualFileSystem::is_vfs_root(InodeIdentifier inode) const
|
|||
return inode == root_inode_id();
|
||||
}
|
||||
|
||||
ErrorOr<void> VirtualFileSystem::traverse_directory_inode(Inode& dir_inode, Function<bool(FileSystem::DirectoryEntryView const&)> callback)
|
||||
ErrorOr<void> VirtualFileSystem::traverse_directory_inode(Inode& dir_inode, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback)
|
||||
{
|
||||
return dir_inode.traverse_as_directory([&](auto& entry) {
|
||||
return dir_inode.traverse_as_directory([&](auto& entry) -> ErrorOr<void> {
|
||||
InodeIdentifier resolved_inode;
|
||||
if (auto mount = find_mount_for_host(entry.inode))
|
||||
resolved_inode = mount->guest().identifier();
|
||||
|
@ -179,8 +179,8 @@ ErrorOr<void> VirtualFileSystem::traverse_directory_inode(Inode& dir_inode, Func
|
|||
VERIFY(mount->host());
|
||||
resolved_inode = mount->host()->identifier();
|
||||
}
|
||||
callback({ entry.name, resolved_inode, entry.file_type });
|
||||
return true;
|
||||
TRY(callback({ entry.name, resolved_inode, entry.file_type }));
|
||||
return {};
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -467,9 +467,9 @@ ErrorOr<void> VirtualFileSystem::rename(StringView old_path, StringView new_path
|
|||
|
||||
if (old_inode.index() != new_inode.index() && old_inode.is_directory() && new_inode.is_directory()) {
|
||||
size_t child_count = 0;
|
||||
TRY(new_inode.traverse_as_directory([&child_count](auto&) {
|
||||
TRY(new_inode.traverse_as_directory([&child_count](auto&) -> ErrorOr<void> {
|
||||
++child_count;
|
||||
return child_count <= 2;
|
||||
return {};
|
||||
}));
|
||||
if (child_count > 2)
|
||||
return ENOTEMPTY;
|
||||
|
@ -710,9 +710,9 @@ ErrorOr<void> VirtualFileSystem::rmdir(StringView path, Custody& base)
|
|||
}
|
||||
|
||||
size_t child_count = 0;
|
||||
TRY(inode.traverse_as_directory([&child_count](auto&) {
|
||||
TRY(inode.traverse_as_directory([&child_count](auto&) -> ErrorOr<void> {
|
||||
++child_count;
|
||||
return true;
|
||||
return {};
|
||||
}));
|
||||
|
||||
if (child_count != 2)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue