1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 13:07:46 +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

@ -31,7 +31,7 @@ ErrorOr<ByteString> current_working_directory()
ErrorOr<ByteString> 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<ByteString> absolute_path(StringView path)
return LexicalPath::absolute_path(working_directory, path);
}
ErrorOr<String> real_path(StringView path)
ErrorOr<ByteString> real_path(StringView path)
{
if (path.is_null())
return Error::from_errno(ENOENT);
@ -52,7 +52,7 @@ ErrorOr<String> 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<void> 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);

View file

@ -20,7 +20,7 @@ namespace FileSystem {
ErrorOr<ByteString> current_working_directory();
ErrorOr<ByteString> absolute_path(StringView path);
ErrorOr<String> real_path(StringView path);
ErrorOr<ByteString> real_path(StringView path);
bool exists(StringView path);
bool exists(int fd);

View file

@ -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 {

View file

@ -144,7 +144,7 @@ Optional<Interface&> 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<Interface>();
auto& interface = *interface_ptr;

View file

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

View file

@ -88,7 +88,7 @@ Optional<URL> sanitize_url(StringView url, Optional<StringView> 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<URL> {