From 8df8f4d75afe763c075bf8107eda81b7139028c7 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Sat, 27 May 2023 12:52:14 +0200 Subject: [PATCH] Shell: Rewrite Shell::runnable_path_for without deprecated API Also, not allocating a vector for the parts should be a tiny bit more efficient. --- Userland/Shell/Shell.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Userland/Shell/Shell.cpp b/Userland/Shell/Shell.cpp index ed8fc81b80..6e8875a07e 100644 --- a/Userland/Shell/Shell.cpp +++ b/Userland/Shell/Shell.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -531,15 +532,16 @@ DeprecatedString Shell::resolve_alias(StringView name) const Optional Shell::runnable_path_for(StringView name) { - auto parts = name.split_view('/'); - auto path = name.to_deprecated_string(); - if (parts.size() > 1) { - auto file = Core::DeprecatedFile::open(path.characters(), Core::OpenMode::ReadOnly); - if (!file.is_error() && !file.value()->is_directory() && access(path.characters(), X_OK) == 0) + auto parts = name.find('/'); + if (parts.has_value()) { + auto file_or_error = Core::File::open(name, Core::File::OpenMode::Read); + if (!file_or_error.is_error() + && !FileSystem::is_directory(file_or_error.value()->fd()) + && !Core::System::access(name, X_OK).is_error()) return RunnablePath { RunnablePath::Kind::Executable, name }; } - auto* found = binary_search(cached_path.span(), path, nullptr, RunnablePathComparator {}); + auto* found = binary_search(cached_path.span(), name, nullptr, RunnablePathComparator {}); if (!found) return {};