1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 14:07:45 +00:00

LibFileSystem+Userland: Return ByteString from real_path()

This commit is contained in:
Sam Atkins 2024-01-15 16:23:24 +00:00 committed by Sam Atkins
parent cdf17efb9a
commit 56c5ffe398
25 changed files with 44 additions and 40 deletions

View file

@ -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;
}

View file

@ -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());

View file

@ -264,7 +264,7 @@ static ErrorOr<TestResult> 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<TestResult> 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<Gfx::Bitmap> actual_screenshot, expectation_screenshot;
view.on_load_finish = [&](auto const&) {
@ -478,7 +478,8 @@ static ErrorOr<void> collect_dump_tests(Vector<Test>& 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<void> collect_ref_tests(Vector<Test>& 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;
}));

View file

@ -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());
}
}

View file

@ -301,6 +301,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (verbose_output)
outln("Reading and parsing Markdown files ...");
// FIXME: Use ByteString for file paths
HashMap<String, MarkdownLinkage> files;
for (auto path : file_paths) {
auto file_or_error = Core::File::open(path, Core::File::OpenMode::Read);
@ -326,7 +327,7 @@ ErrorOr<int> 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)

View file

@ -34,7 +34,7 @@ ErrorOr<int> 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)) {

View file

@ -382,7 +382,7 @@ ErrorOr<int> 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()) {

View file

@ -179,7 +179,7 @@ ErrorOr<int> 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;
}

View file

@ -388,11 +388,11 @@ ErrorOr<int> 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)});
}

View file

@ -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<XML::PublicID> const&) -> ErrorOr<ByteString> {
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();