diff --git a/Userland/Libraries/LibC/unistd.cpp b/Userland/Libraries/LibC/unistd.cpp index ef5f299853b..12864f6a571 100644 --- a/Userland/Libraries/LibC/unistd.cpp +++ b/Userland/Libraries/LibC/unistd.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include @@ -189,7 +189,7 @@ int execvpe(char const* filename, char* const argv[], char* const envp[]) ScopedValueRollback errno_rollback(errno); - // TODO: Make this use the PATH search implementation from Core::DeprecatedFile. + // TODO: Make this use the PATH search implementation from LibFileSystem. DeprecatedString path = getenv("PATH"); if (path.is_empty()) path = DEFAULT_PATH; diff --git a/Userland/Libraries/LibFileSystemAccessClient/Client.cpp b/Userland/Libraries/LibFileSystemAccessClient/Client.cpp index ca5a84e1c8d..5f4a039af53 100644 --- a/Userland/Libraries/LibFileSystemAccessClient/Client.cpp +++ b/Userland/Libraries/LibFileSystemAccessClient/Client.cpp @@ -6,7 +6,6 @@ */ #include -#include #include #include #include @@ -42,7 +41,7 @@ Result Client::request_file_read_only_approved(GUI::Window* parent_window, Depre if (path.starts_with('/')) { async_request_file_read_only_approved(id, parent_window_server_client_id, parent_window_id, path); } else { - auto full_path = LexicalPath::join(Core::DeprecatedFile::current_working_directory(), path).string(); + auto full_path = LexicalPath::join(TRY(FileSystem::current_working_directory()), path).string(); async_request_file_read_only_approved(id, parent_window_server_client_id, parent_window_id, full_path); } @@ -67,7 +66,7 @@ Result Client::request_file(GUI::Window* parent_window, DeprecatedString const& if (path.starts_with('/')) { async_request_file(id, parent_window_server_client_id, parent_window_id, path, mode); } else { - auto full_path = LexicalPath::join(Core::DeprecatedFile::current_working_directory(), path).string(); + auto full_path = LexicalPath::join(TRY(FileSystem::current_working_directory()), path).string(); async_request_file(id, parent_window_server_client_id, parent_window_id, full_path, mode); } diff --git a/Userland/Libraries/LibGUI/FileIconProvider.cpp b/Userland/Libraries/LibGUI/FileIconProvider.cpp index d85ea00612d..a21ee179be6 100644 --- a/Userland/Libraries/LibGUI/FileIconProvider.cpp +++ b/Userland/Libraries/LibGUI/FileIconProvider.cpp @@ -9,10 +9,11 @@ #include #include #include -#include #include #include +#include #include +#include #include #include #include @@ -145,12 +146,12 @@ Icon FileIconProvider::filetype_image_icon() return s_filetype_image_icon; } -Icon FileIconProvider::icon_for_path(DeprecatedString const& path) +Icon FileIconProvider::icon_for_path(StringView path) { - struct stat stat; - if (::stat(path.characters(), &stat) < 0) + auto stat_or_error = Core::System::stat(path); + if (stat_or_error.is_error()) return s_file_icon; - return icon_for_path(path, stat.st_mode); + return icon_for_path(path, stat_or_error.release_value().st_mode); } Icon FileIconProvider::icon_for_executable(DeprecatedString const& path) @@ -238,7 +239,7 @@ Icon FileIconProvider::icon_for_executable(DeprecatedString const& path) return icon; } -Icon FileIconProvider::icon_for_path(DeprecatedString const& path, mode_t mode) +Icon FileIconProvider::icon_for_path(StringView path, mode_t mode) { initialize_if_needed(); if (path == "/") @@ -248,26 +249,27 @@ Icon FileIconProvider::icon_for_path(DeprecatedString const& path, mode_t mode) return s_home_directory_icon; if (path == Core::StandardPaths::desktop_directory()) return s_desktop_directory_icon; - if (access(path.characters(), R_OK | X_OK) < 0) + if (Core::System::access(path, R_OK | X_OK).is_error()) return s_inaccessible_directory_icon; if (path.ends_with(".git"sv)) return s_git_directory_icon; return s_directory_icon; } if (S_ISLNK(mode)) { - auto raw_symlink_target_or_error = Core::DeprecatedFile::read_link(path); + 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(); - if (raw_symlink_target.is_null()) - return s_symlink_icon; - DeprecatedString target_path; + String target_path; if (raw_symlink_target.starts_with('/')) { target_path = raw_symlink_target; } else { - target_path = Core::DeprecatedFile::real_path_for(DeprecatedString::formatted("{}/{}", LexicalPath::dirname(path), raw_symlink_target)); + auto error_or_path = FileSystem::real_path(DeprecatedString::formatted("{}/{}", LexicalPath::dirname(path), raw_symlink_target)); + if (error_or_path.is_error()) + return s_symlink_icon; + + target_path = error_or_path.release_value(); } auto target_icon = icon_for_path(target_path); @@ -295,7 +297,7 @@ Icon FileIconProvider::icon_for_path(DeprecatedString const& path, mode_t mode) if (mode & (S_IXUSR | S_IXGRP | S_IXOTH)) return icon_for_executable(path); - if (Gfx::Bitmap::is_path_a_supported_image_format(path.view())) + if (Gfx::Bitmap::is_path_a_supported_image_format(path)) return s_filetype_image_icon; for (auto& filetype : s_filetype_icons.keys()) { diff --git a/Userland/Libraries/LibGUI/FileIconProvider.h b/Userland/Libraries/LibGUI/FileIconProvider.h index 2bb36932ef0..4807e0cd24b 100644 --- a/Userland/Libraries/LibGUI/FileIconProvider.h +++ b/Userland/Libraries/LibGUI/FileIconProvider.h @@ -14,8 +14,8 @@ namespace GUI { class FileIconProvider { public: - static Icon icon_for_path(DeprecatedString const&, mode_t); - static Icon icon_for_path(DeprecatedString const&); + static Icon icon_for_path(StringView, mode_t); + static Icon icon_for_path(StringView); static Icon icon_for_executable(DeprecatedString const&); static Icon filetype_image_icon(); diff --git a/Userland/Libraries/LibGUI/FileSystemModel.cpp b/Userland/Libraries/LibGUI/FileSystemModel.cpp index a9207ac4497..7c7cae44de8 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.cpp +++ b/Userland/Libraries/LibGUI/FileSystemModel.cpp @@ -11,9 +11,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -63,11 +63,11 @@ bool FileSystemModel::Node::fetch_data(DeprecatedString const& full_path, bool i mtime = st.st_mtime; if (S_ISLNK(mode)) { - auto sym_link_target_or_error = Core::DeprecatedFile::read_link(full_path); + auto sym_link_target_or_error = FileSystem::read_link(full_path); if (sym_link_target_or_error.is_error()) perror("readlink"); else { - symlink_target = sym_link_target_or_error.release_value(); + symlink_target = sym_link_target_or_error.release_value().to_deprecated_string(); if (symlink_target.is_null()) perror("readlink"); } @@ -613,7 +613,7 @@ Variant FileSystemModel::data(ModelIndex const& index, ModelRole role) const Icon FileSystemModel::icon_for(Node const& node) const { if (node.full_path() == "/") - return FileIconProvider::icon_for_path("/"); + return FileIconProvider::icon_for_path("/"sv); if (Gfx::Bitmap::is_path_a_supported_image_format(node.name)) { if (!node.thumbnail) { diff --git a/Userland/Libraries/LibGUI/PathBreadcrumbbar.cpp b/Userland/Libraries/LibGUI/PathBreadcrumbbar.cpp index 062cb423ff6..512e0a42273 100644 --- a/Userland/Libraries/LibGUI/PathBreadcrumbbar.cpp +++ b/Userland/Libraries/LibGUI/PathBreadcrumbbar.cpp @@ -110,7 +110,7 @@ void PathBreadcrumbbar::set_current_path(DeprecatedString const& new_path) } else { m_breadcrumbbar->clear_segments(); - m_breadcrumbbar->append_segment("/", GUI::FileIconProvider::icon_for_path("/").bitmap_for_size(16), "/", "/"); + m_breadcrumbbar->append_segment("/", GUI::FileIconProvider::icon_for_path("/"sv).bitmap_for_size(16), "/", "/"); StringBuilder builder; for (auto& part : lexical_path.parts()) { diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index dd392c06b91..2783b59dc76 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include diff --git a/Userland/Libraries/LibIDL/IDLParser.cpp b/Userland/Libraries/LibIDL/IDLParser.cpp index 22a06bd5285..3b00321ac68 100644 --- a/Userland/Libraries/LibIDL/IDLParser.cpp +++ b/Userland/Libraries/LibIDL/IDLParser.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include @@ -142,7 +141,11 @@ Optional Parser::resolve_import(auto path) if (!FileSystem::exists(include_path)) report_parsing_error(DeprecatedString::formatted("{}: No such file or directory", include_path), filename, input, lexer.tell()); - auto real_path = Core::DeprecatedFile::real_path_for(include_path); + auto real_path_error_or = FileSystem::real_path(include_path); + if (real_path_error_or.is_error()) + report_parsing_error(DeprecatedString::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_deprecated_string(); + if (top_level_resolved_imports().contains(real_path)) return *top_level_resolved_imports().find(real_path)->value; @@ -925,7 +928,12 @@ void resolve_function_typedefs(Interface& interface, FunctionType& function) Interface& Parser::parse() { - auto this_module = Core::DeprecatedFile::real_path_for(filename); + auto this_module_or_error = FileSystem::real_path(filename); + if (this_module_or_error.is_error()) { + report_parsing_error(DeprecatedString::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_deprecated_string(); auto interface_ptr = make(); auto& interface = *interface_ptr; diff --git a/Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp b/Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp index 9fc4fa8ad88..07854ff5e37 100644 --- a/Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp +++ b/Userland/Libraries/LibTest/JavaScriptTestRunnerMain.cpp @@ -7,7 +7,6 @@ */ #include -#include #include #include #include @@ -177,8 +176,19 @@ int main(int argc, char** argv) #endif } - test_root = Core::DeprecatedFile::real_path_for(test_root); - common_path = Core::DeprecatedFile::real_path_for(common_path); + auto test_root_or_error = FileSystem::real_path(test_root); + if (test_root_or_error.is_error()) { + warnln("Failed to resolve test root: {}", test_root_or_error.error()); + return 1; + } + test_root = test_root_or_error.release_value().to_deprecated_string(); + + 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_deprecated_string(); if (chdir(test_root.characters()) < 0) { auto saved_errno = errno;