diff --git a/Userland/Applications/ThemeEditor/main.cpp b/Userland/Applications/ThemeEditor/main.cpp index abaec1a6df..d4a228802e 100644 --- a/Userland/Applications/ThemeEditor/main.cpp +++ b/Userland/Applications/ThemeEditor/main.cpp @@ -37,7 +37,7 @@ ErrorOr serenity_main(Main::Arguments arguments) parser.add_positional_argument(file_to_edit, "Theme file to edit", "file", Core::ArgsParser::Required::No); parser.parse(arguments); - Optional path = {}; + Optional path = {}; if (auto error_or_path = FileSystem::absolute_path(file_to_edit); !file_to_edit.is_empty() && !error_or_path.is_error()) path = error_or_path.release_value(); @@ -57,7 +57,7 @@ ErrorOr serenity_main(Main::Arguments arguments) // Note: This is deferred to ensure that the window has already popped and any error dialog boxes would show up correctly. app->event_loop().deferred_invoke( [&window, &path, &main_widget]() { - auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, path.value().to_byte_string()); + auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, path.value()); if (!response.is_error()) { auto load_from_file_result = main_widget->load_from_file(response.value().filename(), response.value().release_stream()); if (load_from_file_result.is_error()) diff --git a/Userland/Libraries/LibFileSystem/FileSystem.cpp b/Userland/Libraries/LibFileSystem/FileSystem.cpp index e1a930ac29..713fa90894 100644 --- a/Userland/Libraries/LibFileSystem/FileSystem.cpp +++ b/Userland/Libraries/LibFileSystem/FileSystem.cpp @@ -28,18 +28,16 @@ ErrorOr current_working_directory() return Core::System::getcwd(); } -ErrorOr absolute_path(StringView path) +ErrorOr absolute_path(StringView path) { if (exists(path)) - return TRY(real_path(path)); + return TRY(real_path(path)).to_byte_string(); if (path.starts_with("/"sv)) - return TRY(String::from_byte_string(LexicalPath::canonicalized_path(path))); + return LexicalPath::canonicalized_path(path); auto working_directory = TRY(current_working_directory()); - auto full_path = LexicalPath::join(working_directory, path).string(); - - return TRY(String::from_byte_string(LexicalPath::canonicalized_path(full_path))); + return LexicalPath::absolute_path(working_directory, path); } ErrorOr real_path(StringView path) diff --git a/Userland/Libraries/LibFileSystem/FileSystem.h b/Userland/Libraries/LibFileSystem/FileSystem.h index 6f2171016f..57787682eb 100644 --- a/Userland/Libraries/LibFileSystem/FileSystem.h +++ b/Userland/Libraries/LibFileSystem/FileSystem.h @@ -19,7 +19,7 @@ namespace FileSystem { #define DEFAULT_PATH_SV "/usr/local/sbin:/usr/local/bin:/usr/bin:/bin"sv ErrorOr current_working_directory(); -ErrorOr absolute_path(StringView path); +ErrorOr absolute_path(StringView path); ErrorOr real_path(StringView path); bool exists(StringView path); diff --git a/Userland/Utilities/install.cpp b/Userland/Utilities/install.cpp index b9ff71ed34..d9d5ec9001 100644 --- a/Userland/Utilities/install.cpp +++ b/Userland/Utilities/install.cpp @@ -35,8 +35,8 @@ ErrorOr serenity_main(Main::Arguments arguments) ByteString destination_dir = (sources.size() > 1 ? ByteString { destination } : LexicalPath::dirname(destination)); if (create_leading_dest_components) { - String destination_dir_absolute = TRY(FileSystem::absolute_path(destination_dir)); - MUST(Core::Directory::create(destination_dir_absolute.to_byte_string(), Core::Directory::CreateDirectories::Yes)); + auto destination_dir_absolute = TRY(FileSystem::absolute_path(destination_dir)); + MUST(Core::Directory::create(destination_dir_absolute, Core::Directory::CreateDirectories::Yes)); } for (auto const& source : sources) { diff --git a/Userland/Utilities/mktemp.cpp b/Userland/Utilities/mktemp.cpp index cf64e6fd58..5981d6fab9 100644 --- a/Userland/Utilities/mktemp.cpp +++ b/Userland/Utilities/mktemp.cpp @@ -76,7 +76,7 @@ ErrorOr serenity_main(Main::Arguments arguments) if (target_directory.is_empty()) { if (!file_template.is_empty()) { - auto resolved_path = LexicalPath(TRY(FileSystem::absolute_path(file_template)).to_byte_string()); + auto resolved_path = LexicalPath(TRY(FileSystem::absolute_path(file_template))); final_target_directory = TRY(String::from_utf8(resolved_path.dirname())); final_file_template = TRY(String::from_utf8(resolved_path.basename())); } else { diff --git a/Userland/Utilities/sed.cpp b/Userland/Utilities/sed.cpp index 4d5c890751..dcb78b62ff 100644 --- a/Userland/Utilities/sed.cpp +++ b/Userland/Utilities/sed.cpp @@ -952,7 +952,7 @@ ErrorOr serenity_main(Main::Arguments args) pos_args.remove(0); } - HashMap paths_to_unveil; + HashMap paths_to_unveil; for (auto const& input_filename : TRY(script.input_filenames())) { TRY(paths_to_unveil.try_set(TRY(FileSystem::absolute_path(input_filename)), edit_in_place ? "rwc"_string : "r"_string)); diff --git a/Userland/Utilities/tar.cpp b/Userland/Utilities/tar.cpp index a0ed7ccebb..1f434f8c33 100644 --- a/Userland/Utilities/tar.cpp +++ b/Userland/Utilities/tar.cpp @@ -167,7 +167,7 @@ ErrorOr serenity_main(Main::Arguments arguments) outln("{}", filename); if (extract) { - ByteString absolute_path = TRY(FileSystem::absolute_path(filename)).to_byte_string(); + auto absolute_path = TRY(FileSystem::absolute_path(filename)); auto parent_path = LexicalPath(absolute_path).parent(); auto header_mode = TRY(header.mode());