1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:47:44 +00:00

Kernel: Custody::absolute_path() => try_create_absolute_path()

This converts most users of Custody::absolute_path() to use the new
try_create_absolute_path() API, and return ENOMEM if the KString
allocation fails.
This commit is contained in:
Max Wipfli 2021-07-06 12:58:03 +02:00 committed by Andreas Kling
parent 0f8a6e574c
commit d5722eab36
4 changed files with 32 additions and 15 deletions

View file

@ -86,19 +86,25 @@ KResultOr<FlatPtr> Process::sys$unveil(Userspace<const Syscall::SC_unveil_params
// because they most likely intend the program to create the file for them later on.
// If this case is encountered, the parent node of the path is returned and the custody of that inode is used instead.
RefPtr<Custody> parent_custody; // Parent inode in case of ENOENT
String new_unveiled_path;
OwnPtr<KString> new_unveiled_path;
auto custody_or_error = VFS::the().resolve_path_without_veil(path.view(), root_directory(), &parent_custody);
if (!custody_or_error.is_error()) {
new_unveiled_path = custody_or_error.value()->absolute_path();
new_unveiled_path = custody_or_error.value()->try_create_absolute_path();
if (!new_unveiled_path)
return ENOMEM;
} else if (custody_or_error.error() == -ENOENT && parent_custody && (new_permissions & UnveilAccess::CreateOrRemove)) {
auto basename = KLexicalPath::basename(path.view());
new_unveiled_path = String::formatted("{}/{}", parent_custody->absolute_path(), basename);
auto parent_custody_path = parent_custody->try_create_absolute_path();
if (!parent_custody_path)
return ENOMEM;
new_unveiled_path = KLexicalPath::try_join(parent_custody_path->view(), KLexicalPath::basename(path.view()));
if (!new_unveiled_path)
return ENOMEM;
} else {
// FIXME Should this be EINVAL?
return custody_or_error.error();
}
auto path_parts = KLexicalPath::parts(new_unveiled_path);
auto path_parts = KLexicalPath::parts(new_unveiled_path->view());
auto it = path_parts.begin();
auto& matching_node = m_unveiled_paths.traverse_until_last_accessible_node(it, path_parts.end());
if (it.is_end()) {
@ -123,7 +129,7 @@ KResultOr<FlatPtr> Process::sys$unveil(Userspace<const Syscall::SC_unveil_params
matching_node.insert(
it,
path_parts.end(),
{ new_unveiled_path, (UnveilAccess)new_permissions, true },
{ new_unveiled_path->view(), (UnveilAccess)new_permissions, true },
[](auto& parent, auto& it) -> Optional<UnveilMetadata> {
auto path = String::formatted("{}/{}", parent.path(), *it);
return UnveilMetadata { path, parent.permissions(), false };