mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:18:11 +00:00
Kernel: Remove an allocation from VFS::resolve_path_without_veil (#7287)
Use GenericLexer to replace a call to StringView::split() since that returns its result in a heap-allocating Vector.
This commit is contained in:
parent
467ceb15aa
commit
e16a50b586
1 changed files with 9 additions and 4 deletions
|
@ -941,13 +941,19 @@ KResultOr<NonnullRefPtr<Custody>> VFS::resolve_path_without_veil(StringView path
|
||||||
if (path.is_empty())
|
if (path.is_empty())
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
auto parts = path.split_view('/', true);
|
GenericLexer path_lexer(path);
|
||||||
auto current_process = Process::current();
|
auto current_process = Process::current();
|
||||||
auto& current_root = current_process->root_directory();
|
auto& current_root = current_process->root_directory();
|
||||||
|
|
||||||
NonnullRefPtr<Custody> custody = path[0] == '/' ? current_root : base;
|
NonnullRefPtr<Custody> custody = path[0] == '/' ? current_root : base;
|
||||||
|
bool extra_iteration = path[path.length() - 1] == '/';
|
||||||
|
|
||||||
|
while (!path_lexer.is_eof() || extra_iteration) {
|
||||||
|
if (path_lexer.is_eof())
|
||||||
|
extra_iteration = false;
|
||||||
|
auto part = path_lexer.consume_until('/');
|
||||||
|
path_lexer.consume_specific('/');
|
||||||
|
|
||||||
for (size_t i = 0; i < parts.size(); ++i) {
|
|
||||||
Custody& parent = custody;
|
Custody& parent = custody;
|
||||||
auto parent_metadata = parent.inode().metadata();
|
auto parent_metadata = parent.inode().metadata();
|
||||||
if (!parent_metadata.is_directory())
|
if (!parent_metadata.is_directory())
|
||||||
|
@ -956,8 +962,7 @@ KResultOr<NonnullRefPtr<Custody>> VFS::resolve_path_without_veil(StringView path
|
||||||
if (!parent_metadata.may_execute(*current_process))
|
if (!parent_metadata.may_execute(*current_process))
|
||||||
return EACCES;
|
return EACCES;
|
||||||
|
|
||||||
auto& part = parts[i];
|
bool have_more_parts = !path_lexer.is_eof() || extra_iteration;
|
||||||
bool have_more_parts = i + 1 < parts.size();
|
|
||||||
|
|
||||||
if (part == "..") {
|
if (part == "..") {
|
||||||
// If we encounter a "..", take a step back, but don't go beyond the root.
|
// If we encounter a "..", take a step back, but don't go beyond the root.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue