diff --git a/Userland/Applications/FileManager/DirectoryView.cpp b/Userland/Applications/FileManager/DirectoryView.cpp index 7447e62d211..541667669ef 100644 --- a/Userland/Applications/FileManager/DirectoryView.cpp +++ b/Userland/Applications/FileManager/DirectoryView.cpp @@ -413,11 +413,11 @@ bool DirectoryView::open(ByteString const& path) warnln("Failed to open '{}': {}", real_path, result.error()); } - if (model().root_path() == real_path.to_byte_string()) { + if (model().root_path() == real_path) { refresh(); } else { set_active_widget(¤t_view()); - model().set_root_path(real_path.to_byte_string()); + model().set_root_path(real_path); } return true; } diff --git a/Userland/Applications/FileManager/main.cpp b/Userland/Applications/FileManager/main.cpp index 8863954863d..7cadff815de 100644 --- a/Userland/Applications/FileManager/main.cpp +++ b/Userland/Applications/FileManager/main.cpp @@ -109,7 +109,7 @@ ErrorOr serenity_main(Main::Arguments arguments) LexicalPath path(initial_location); if (!initial_location.is_empty()) { if (auto error_or_path = FileSystem::real_path(initial_location); !ignore_path_resolution && !error_or_path.is_error()) - initial_location = error_or_path.release_value().to_byte_string(); + initial_location = error_or_path.release_value(); if (!FileSystem::is_directory(initial_location)) { // We want to extract zips to a temporary directory when FileManager is launched with a .zip file as its first argument diff --git a/Userland/Applications/Run/RunWindow.cpp b/Userland/Applications/Run/RunWindow.cpp index 2b8246bff53..8282d6d9726 100644 --- a/Userland/Applications/Run/RunWindow.cpp +++ b/Userland/Applications/Run/RunWindow.cpp @@ -147,7 +147,7 @@ bool RunWindow::run_via_launch(ByteString const& run_input) warnln("Failed to launch '{}': {}", file_path, real_path_or_error.error()); return false; } - url = URL::create_with_url_or_path(real_path_or_error.release_value().to_byte_string()); + url = URL::create_with_url_or_path(real_path_or_error.release_value()); } if (!Desktop::Launcher::open(url)) { diff --git a/Userland/DevTools/HackStudio/main.cpp b/Userland/DevTools/HackStudio/main.cpp index 197e98f3c7a..31a9ca8a567 100644 --- a/Userland/DevTools/HackStudio/main.cpp +++ b/Userland/DevTools/HackStudio/main.cpp @@ -228,7 +228,7 @@ static ErrorOr> create_hack_studio_widget(bool m else if (auto last_path = last_opened_project_path(); last_path.has_value()) project_path = last_path.release_value(); else - project_path = TRY(FileSystem::real_path("."sv)).to_byte_string(); + project_path = TRY(FileSystem::real_path("."sv)); return HackStudioWidget::create(project_path); } diff --git a/Userland/Libraries/LibFileSystem/FileSystem.cpp b/Userland/Libraries/LibFileSystem/FileSystem.cpp index 713fa908949..662b1c43c45 100644 --- a/Userland/Libraries/LibFileSystem/FileSystem.cpp +++ b/Userland/Libraries/LibFileSystem/FileSystem.cpp @@ -31,7 +31,7 @@ ErrorOr current_working_directory() ErrorOr absolute_path(StringView path) { if (exists(path)) - return TRY(real_path(path)).to_byte_string(); + return real_path(path); if (path.starts_with("/"sv)) return LexicalPath::canonicalized_path(path); @@ -40,7 +40,7 @@ ErrorOr absolute_path(StringView path) return LexicalPath::absolute_path(working_directory, path); } -ErrorOr real_path(StringView path) +ErrorOr real_path(StringView path) { if (path.is_null()) return Error::from_errno(ENOENT); @@ -52,7 +52,7 @@ ErrorOr real_path(StringView path) if (!real_path) return Error::from_syscall("realpath"sv, -errno); - return TRY(String::from_utf8({ real_path, strlen(real_path) })); + return ByteString { real_path, strlen(real_path) }; } bool exists(StringView path) @@ -244,12 +244,12 @@ ErrorOr copy_directory(StringView destination_path, StringView source_path TRY(Core::System::mkdir(destination_path, 0755)); auto source_rp = TRY(real_path(source_path)); - source_rp = TRY(String::formatted("{}/", source_rp)); + source_rp = ByteString::formatted("{}/", source_rp); auto destination_rp = TRY(real_path(destination_path)); - destination_rp = TRY(String::formatted("{}/", destination_rp)); + destination_rp = ByteString::formatted("{}/", destination_rp); - if (!destination_rp.is_empty() && destination_rp.starts_with_bytes(source_rp)) + if (!destination_rp.is_empty() && destination_rp.starts_with(source_rp)) return Error::from_errno(EINVAL); Core::DirIterator di(source_path, Core::DirIterator::SkipParentAndBaseDir); diff --git a/Userland/Libraries/LibFileSystem/FileSystem.h b/Userland/Libraries/LibFileSystem/FileSystem.h index 57787682eb5..b7c22fdf825 100644 --- a/Userland/Libraries/LibFileSystem/FileSystem.h +++ b/Userland/Libraries/LibFileSystem/FileSystem.h @@ -20,7 +20,7 @@ namespace FileSystem { ErrorOr current_working_directory(); ErrorOr absolute_path(StringView path); -ErrorOr real_path(StringView path); +ErrorOr real_path(StringView path); bool exists(StringView path); bool exists(int fd); diff --git a/Userland/Libraries/LibGUI/FileIconProvider.cpp b/Userland/Libraries/LibGUI/FileIconProvider.cpp index 4a05b00b4a6..fb6e6767f30 100644 --- a/Userland/Libraries/LibGUI/FileIconProvider.cpp +++ b/Userland/Libraries/LibGUI/FileIconProvider.cpp @@ -259,9 +259,9 @@ Icon FileIconProvider::icon_for_path(StringView path, mode_t mode) auto raw_symlink_target_or_error = FileSystem::read_link(path); if (raw_symlink_target_or_error.is_error()) return s_symlink_icon; - auto raw_symlink_target = raw_symlink_target_or_error.release_value(); + auto raw_symlink_target = raw_symlink_target_or_error.release_value().to_byte_string(); - String target_path; + ByteString target_path; if (raw_symlink_target.starts_with('/')) { target_path = raw_symlink_target; } else { diff --git a/Userland/Libraries/LibIDL/IDLParser.cpp b/Userland/Libraries/LibIDL/IDLParser.cpp index 5abb23c439c..53ce4001572 100644 --- a/Userland/Libraries/LibIDL/IDLParser.cpp +++ b/Userland/Libraries/LibIDL/IDLParser.cpp @@ -144,7 +144,7 @@ Optional Parser::resolve_import(auto path) auto real_path_error_or = FileSystem::real_path(include_path); if (real_path_error_or.is_error()) report_parsing_error(ByteString::formatted("Failed to resolve path {}: {}", include_path, real_path_error_or.error()), filename, input, lexer.tell()); - auto real_path = real_path_error_or.release_value().to_byte_string(); + auto real_path = real_path_error_or.release_value(); if (top_level_resolved_imports().contains(real_path)) return *top_level_resolved_imports().find(real_path)->value; @@ -966,7 +966,7 @@ Interface& Parser::parse() report_parsing_error(ByteString::formatted("Failed to resolve path '{}': {}", filename, this_module_or_error.error()), filename, input, 0); VERIFY_NOT_REACHED(); } - auto this_module = this_module_or_error.release_value().to_byte_string(); + auto this_module = this_module_or_error.release_value(); auto interface_ptr = make(); auto& interface = *interface_ptr; diff --git a/Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp b/Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp index 0111996162a..cdfd6394156 100644 --- a/Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp +++ b/Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp @@ -174,14 +174,14 @@ int main(int argc, char** argv) warnln("Failed to resolve test root: {}", test_root_or_error.error()); return 1; } - test_root = test_root_or_error.release_value().to_byte_string(); + test_root = test_root_or_error.release_value(); auto common_path_or_error = FileSystem::real_path(common_path); if (common_path_or_error.is_error()) { warnln("Failed to resolve common path: {}", common_path_or_error.error()); return 1; } - common_path = common_path_or_error.release_value().to_byte_string(); + common_path = common_path_or_error.release_value(); if (chdir(test_root.characters()) < 0) { auto saved_errno = errno; diff --git a/Userland/Libraries/LibWebView/URL.cpp b/Userland/Libraries/LibWebView/URL.cpp index 8898d232163..21abbf47669 100644 --- a/Userland/Libraries/LibWebView/URL.cpp +++ b/Userland/Libraries/LibWebView/URL.cpp @@ -88,7 +88,7 @@ Optional sanitize_url(StringView url, Optional search_engine, A if (path.is_error()) return {}; - return URL::create_with_file_scheme(path.value().to_byte_string()); + return URL::create_with_file_scheme(path.value()); } auto format_search_engine = [&]() -> Optional { diff --git a/Userland/Services/FileSystemAccessServer/ConnectionFromClient.cpp b/Userland/Services/FileSystemAccessServer/ConnectionFromClient.cpp index 9040f6a041f..a22d413007f 100644 --- a/Userland/Services/FileSystemAccessServer/ConnectionFromClient.cpp +++ b/Userland/Services/FileSystemAccessServer/ConnectionFromClient.cpp @@ -56,7 +56,7 @@ void ConnectionFromClient::request_file_handler(i32 request_id, i32 window_serve if (prompt == ShouldPrompt::Yes) { VERIFY(window_server_client_id != -1 && parent_window_id != -1); - auto exe_name = LexicalPath::basename(exe_path.to_byte_string()); + auto exe_name = LexicalPath::basename(exe_path); auto text = String::formatted("Allow {} ({}) to {} \"{}\"?", exe_name, pid, access_string, path).release_value_but_fixme_should_propagate_errors(); auto result = GUI::MessageBox::try_show({}, window_server_client_id, parent_window_id, text, "File Permissions Requested"sv).release_value_but_fixme_should_propagate_errors(); approved = result == GUI::MessageBox::ExecResult::Yes; diff --git a/Userland/Services/LaunchServer/Launcher.cpp b/Userland/Services/LaunchServer/Launcher.cpp index c480b374681..21a9a785167 100644 --- a/Userland/Services/LaunchServer/Launcher.cpp +++ b/Userland/Services/LaunchServer/Launcher.cpp @@ -318,7 +318,7 @@ void Launcher::for_each_handler_for_path(ByteString const& path, Function bool { + return for_each_handler_for_path(real_path, [&](auto const& handler) -> bool { return f(handler); }); } diff --git a/Userland/Services/WebServer/main.cpp b/Userland/Services/WebServer/main.cpp index f7f7b8c308f..c9794056dbc 100644 --- a/Userland/Services/WebServer/main.cpp +++ b/Userland/Services/WebServer/main.cpp @@ -68,7 +68,8 @@ ErrorOr serenity_main(Main::Arguments arguments) if (!username.is_empty() && !password.is_empty()) credentials = HTTP::HttpRequest::BasicAuthenticationCredentials { username, password }; - WebServer::Configuration configuration(real_document_root_path, credentials); + // FIXME: This should accept a ByteString for the path instead. + WebServer::Configuration configuration(TRY(String::from_byte_string(real_document_root_path)), credentials); Core::EventLoop loop; diff --git a/Userland/Shell/Builtin.cpp b/Userland/Shell/Builtin.cpp index 01e8e716bb6..2e6b80009aa 100644 --- a/Userland/Shell/Builtin.cpp +++ b/Userland/Shell/Builtin.cpp @@ -454,7 +454,7 @@ ErrorOr Shell::builtin_cd(Main::Arguments arguments) warnln("Invalid path '{}'", new_path); return 1; } - auto real_path = real_path_or_error.release_value().to_byte_string(); + auto real_path = real_path_or_error.release_value(); if (cd_history.is_empty() || cd_history.last() != real_path) cd_history.enqueue(real_path); diff --git a/Userland/Shell/Shell.cpp b/Userland/Shell/Shell.cpp index 89228701d7c..f7b33802eb8 100644 --- a/Userland/Shell/Shell.cpp +++ b/Userland/Shell/Shell.cpp @@ -394,7 +394,7 @@ ByteString Shell::resolve_path(ByteString path) const if (!path.starts_with('/')) path = ByteString::formatted("{}/{}", cwd, path); - return FileSystem::real_path(path).release_value_but_fixme_should_propagate_errors().to_byte_string(); + return FileSystem::real_path(path).release_value_but_fixme_should_propagate_errors(); } Shell::LocalFrame* Shell::find_frame_containing_local_variable(StringView name) diff --git a/Userland/Utilities/find.cpp b/Userland/Utilities/find.cpp index 2711654cfe7..ed2d2beaa1c 100644 --- a/Userland/Utilities/find.cpp +++ b/Userland/Utilities/find.cpp @@ -579,7 +579,7 @@ private: auto full_path_or_error = FileSystem::real_path(file_data.full_path()); if (!full_path_or_error.is_error()) { auto fullpath = full_path_or_error.release_value(); - auto url = URL::create_with_file_scheme(fullpath.to_byte_string()); + auto url = URL::create_with_file_scheme(fullpath); out("\033]8;;{}\033\\{}{}\033]8;;\033\\", url.serialize(), file_data.full_path(), m_terminator); printed = true; } diff --git a/Userland/Utilities/grep.cpp b/Userland/Utilities/grep.cpp index d9a85f765b4..11bd3a00b3e 100644 --- a/Userland/Utilities/grep.cpp +++ b/Userland/Utilities/grep.cpp @@ -88,7 +88,7 @@ static void append_formatted_path(StringBuilder& builder, StringView path, Optio auto full_path_or_error = FileSystem::real_path(path); if (!full_path_or_error.is_error()) { auto fullpath = full_path_or_error.release_value(); - auto url = URL::create_with_file_scheme(fullpath.to_byte_string(), {}, hostname()); + auto url = URL::create_with_file_scheme(fullpath, {}, hostname()); if (has_flag(print_type, PrintType::LineNumbers) && line_number.has_value()) url.set_query(MUST(String::formatted("line_number={}", *line_number))); builder.appendff("\033]8;;{}\033\\", url.serialize()); diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp index 88d1a5b5795..2e4783dc08a 100644 --- a/Userland/Utilities/headless-browser.cpp +++ b/Userland/Utilities/headless-browser.cpp @@ -264,7 +264,7 @@ static ErrorOr run_dump_test(HeadlessWebContentView& view, StringVie loop.quit(0); })); - auto url = URL::create_with_file_scheme(TRY(FileSystem::real_path(input_path)).to_byte_string()); + auto url = URL::create_with_file_scheme(TRY(FileSystem::real_path(input_path))); String result; auto did_finish_test = false; @@ -359,7 +359,7 @@ static ErrorOr run_ref_test(HeadlessWebContentView& view, StringView loop.quit(0); })); - view.load(URL::create_with_file_scheme(TRY(FileSystem::real_path(input_path)).to_byte_string())); + view.load(URL::create_with_file_scheme(TRY(FileSystem::real_path(input_path)))); RefPtr actual_screenshot, expectation_screenshot; view.on_load_finish = [&](auto const&) { @@ -478,7 +478,8 @@ static ErrorOr collect_dump_tests(Vector& tests, StringView path, St auto basename = LexicalPath::title(name); auto expectation_path = TRY(String::formatted("{}/expected/{}/{}.txt", path, trail, basename)); - tests.append({ move(input_path), move(expectation_path), mode, {} }); + // FIXME: Test paths should be ByteString + tests.append({ TRY(String::from_byte_string(input_path)), move(expectation_path), mode, {} }); } return {}; } @@ -489,7 +490,8 @@ static ErrorOr collect_ref_tests(Vector& tests, StringView path) if (entry.type == Core::DirectoryEntry::Type::Directory) return IterationDecision::Continue; auto input_path = TRY(FileSystem::real_path(TRY(String::formatted("{}/{}", path, entry.name)))); - tests.append({ move(input_path), {}, TestMode::Ref, {} }); + // FIXME: Test paths should be ByteString + tests.append({ TRY(String::from_byte_string(input_path)), {}, TestMode::Ref, {} }); return IterationDecision::Continue; })); diff --git a/Userland/Utilities/ls.cpp b/Userland/Utilities/ls.cpp index adcc6006efd..2e267cefd44 100644 --- a/Userland/Utilities/ls.cpp +++ b/Userland/Utilities/ls.cpp @@ -267,7 +267,7 @@ static size_t print_name(const struct stat& st, ByteString const& name, Optional auto full_path_or_error = FileSystem::real_path(path_for_hyperlink); if (!full_path_or_error.is_error()) { auto fullpath = full_path_or_error.release_value(); - auto url = URL::create_with_file_scheme(fullpath.to_byte_string(), {}, hostname()); + auto url = URL::create_with_file_scheme(fullpath, {}, hostname()); out("\033]8;;{}\033\\", url.serialize()); } } diff --git a/Userland/Utilities/markdown-check.cpp b/Userland/Utilities/markdown-check.cpp index 8457b0a1620..19a820dd2f6 100644 --- a/Userland/Utilities/markdown-check.cpp +++ b/Userland/Utilities/markdown-check.cpp @@ -301,6 +301,7 @@ ErrorOr serenity_main(Main::Arguments arguments) if (verbose_output) outln("Reading and parsing Markdown files ..."); + // FIXME: Use ByteString for file paths HashMap files; for (auto path : file_paths) { auto file_or_error = Core::File::open(path, Core::File::OpenMode::Read); @@ -326,7 +327,7 @@ ErrorOr serenity_main(Main::Arguments arguments) // Since this should never happen anyway, fail early. return 1; } - files.set(TRY(FileSystem::real_path(path)), MarkdownLinkage::analyze(*document, verbose_output)); + files.set(TRY(String::from_byte_string(TRY(FileSystem::real_path(path)))), MarkdownLinkage::analyze(*document, verbose_output)); } if (verbose_output) diff --git a/Userland/Utilities/open.cpp b/Userland/Utilities/open.cpp index 5eb25e73a4d..561996d3ca8 100644 --- a/Userland/Utilities/open.cpp +++ b/Userland/Utilities/open.cpp @@ -34,7 +34,7 @@ ErrorOr serenity_main(Main::Arguments arguments) continue; } } else { - url = URL::create_with_url_or_path(path_or_error.value().to_byte_string()); + url = URL::create_with_url_or_path(path_or_error.value()); } if (!Desktop::Launcher::open(url)) { diff --git a/Userland/Utilities/run-tests.cpp b/Userland/Utilities/run-tests.cpp index b6727e449f6..a1825b16d03 100644 --- a/Userland/Utilities/run-tests.cpp +++ b/Userland/Utilities/run-tests.cpp @@ -382,7 +382,7 @@ ErrorOr serenity_main(Main::Arguments arguments) return 1; } - test_root = TRY(FileSystem::real_path(test_root)).to_byte_string(); + test_root = TRY(FileSystem::real_path(test_root)); auto void_or_error = Core::System::chdir(test_root); if (void_or_error.is_error()) { diff --git a/Userland/Utilities/shot.cpp b/Userland/Utilities/shot.cpp index 421b05ce148..51fd4302d8c 100644 --- a/Userland/Utilities/shot.cpp +++ b/Userland/Utilities/shot.cpp @@ -179,7 +179,7 @@ ErrorOr serenity_main(Main::Arguments arguments) char hostname[HOST_NAME_MAX]; VERIFY(gethostname(hostname, sizeof(hostname)) == 0); - auto url = URL::create_with_file_scheme(full_path_or_error.value().to_byte_string(), {}, hostname); + auto url = URL::create_with_file_scheme(full_path_or_error.value(), {}, hostname); out("\033]8;;{}\033\\", url.serialize()); printed_hyperlink = true; } diff --git a/Userland/Utilities/wasm.cpp b/Userland/Utilities/wasm.cpp index ce766e4fa7b..f965b81a7fd 100644 --- a/Userland/Utilities/wasm.cpp +++ b/Userland/Utilities/wasm.cpp @@ -388,11 +388,11 @@ ErrorOr serenity_main(Main::Arguments arguments) for (auto& string : wasi_preopened_mappings) { auto split_index = string.find(':'); if (split_index.has_value()) { - LexicalPath host_path { FileSystem::real_path(string.substring_view(0, *split_index)).release_value_but_fixme_should_propagate_errors().to_byte_string() }; + LexicalPath host_path { FileSystem::real_path(string.substring_view(0, *split_index)).release_value_but_fixme_should_propagate_errors() }; LexicalPath mapped_path { string.substring_view(*split_index + 1) }; paths.append({move(host_path), move(mapped_path)}); } else { - LexicalPath host_path { FileSystem::real_path(string).release_value_but_fixme_should_propagate_errors().to_byte_string() }; + LexicalPath host_path { FileSystem::real_path(string).release_value_but_fixme_should_propagate_errors() }; LexicalPath mapped_path { string }; paths.append({move(host_path), move(mapped_path)}); } diff --git a/Userland/Utilities/xml.cpp b/Userland/Utilities/xml.cpp index b4fddd64744..444cfabb8a2 100644 --- a/Userland/Utilities/xml.cpp +++ b/Userland/Utilities/xml.cpp @@ -355,7 +355,7 @@ static void dump(XML::Document& document) dump(document.root()); } -static String s_path; +static ByteString s_path; static auto parse(StringView contents) { return XML::Parser { @@ -363,7 +363,7 @@ static auto parse(StringView contents) { .preserve_comments = true, .resolve_external_resource = [&](XML::SystemID const& system_id, Optional const&) -> ErrorOr { - auto base = URL::create_with_file_scheme(s_path.to_byte_string()); + auto base = URL::create_with_file_scheme(s_path); auto url = URLParser::basic_parse(system_id.system_literal, base); if (!url.is_valid()) return Error::from_string_literal("Invalid URL"); @@ -402,7 +402,7 @@ static void do_run_tests(XML::Document& document) dump_cases(root); - auto base_path = LexicalPath::dirname(s_path.to_byte_string()); + auto base_path = LexicalPath::dirname(s_path); while (!suites.is_empty()) { auto& node = *suites.dequeue();