mirror of
https://github.com/RGBCube/serenity
synced 2025-05-19 00:45:08 +00:00
AK+Everywhere: Add and use static APIs for LexicalPath
The LexicalPath instance methods dirname(), basename(), title() and extension() will be changed to return StringView const& in a further commit. Due to this, users creating temporary LexicalPath objects just to call one of those getters will recieve a StringView const& pointing to a possible freed buffer. To avoid this, static methods for those APIs have been added, which will return a String by value to avoid those problems. All cases where temporary LexicalPath objects have been used as described above haven been changed to use the static APIs.
This commit is contained in:
parent
9b8f35259c
commit
fc6d051dfd
43 changed files with 80 additions and 56 deletions
|
@ -533,7 +533,7 @@ KResult VFS::rename(StringView old_path, StringView new_path, Custody& base)
|
|||
if (old_parent_custody->is_readonly() || new_parent_custody->is_readonly())
|
||||
return EROFS;
|
||||
|
||||
auto new_basename = LexicalPath(new_path).basename();
|
||||
auto new_basename = LexicalPath::basename(new_path);
|
||||
|
||||
if (!new_custody_or_error.is_error()) {
|
||||
auto& new_custody = *new_custody_or_error.value();
|
||||
|
@ -554,7 +554,7 @@ KResult VFS::rename(StringView old_path, StringView new_path, Custody& base)
|
|||
if (auto result = new_parent_inode.add_child(old_inode, new_basename, old_inode.mode()); result.is_error())
|
||||
return result;
|
||||
|
||||
if (auto result = old_parent_inode.remove_child(LexicalPath(old_path).basename()); result.is_error())
|
||||
if (auto result = old_parent_inode.remove_child(LexicalPath::basename(old_path)); result.is_error())
|
||||
return result;
|
||||
|
||||
return KSuccess;
|
||||
|
@ -656,7 +656,7 @@ KResult VFS::link(StringView old_path, StringView new_path, Custody& base)
|
|||
if (!hard_link_allowed(old_inode))
|
||||
return EPERM;
|
||||
|
||||
return parent_inode.add_child(old_inode, LexicalPath(new_path).basename(), old_inode.mode());
|
||||
return parent_inode.add_child(old_inode, LexicalPath::basename(new_path), old_inode.mode());
|
||||
}
|
||||
|
||||
KResult VFS::unlink(StringView path, Custody& base)
|
||||
|
@ -689,7 +689,7 @@ KResult VFS::unlink(StringView path, Custody& base)
|
|||
if (parent_custody->is_readonly())
|
||||
return EROFS;
|
||||
|
||||
if (auto result = parent_inode.remove_child(LexicalPath(path).basename()); result.is_error())
|
||||
if (auto result = parent_inode.remove_child(LexicalPath::basename(path)); result.is_error())
|
||||
return result;
|
||||
|
||||
return KSuccess;
|
||||
|
@ -771,7 +771,7 @@ KResult VFS::rmdir(StringView path, Custody& base)
|
|||
if (auto result = inode.remove_child(".."); result.is_error())
|
||||
return result;
|
||||
|
||||
return parent_inode.remove_child(LexicalPath(path).basename());
|
||||
return parent_inode.remove_child(LexicalPath::basename(path));
|
||||
}
|
||||
|
||||
VFS::Mount::Mount(FS& guest_fs, Custody* host_custody, int flags)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue