Преглед на файлове

Applications: Convert `DeprecatedFile` usages to `LibFileSystem`

Cameron Youell преди 2 години
родител
ревизия
1dc3ba6ed5

+ 0 - 1
Userland/Applications/3DFileViewer/WavefrontOBJLoader.cpp

@@ -9,7 +9,6 @@
 #include "WavefrontOBJLoader.h"
 #include "WavefrontOBJLoader.h"
 #include <AK/FixedArray.h>
 #include <AK/FixedArray.h>
 #include <AK/String.h>
 #include <AK/String.h>
-#include <LibCore/DeprecatedFile.h>
 #include <LibCore/File.h>
 #include <LibCore/File.h>
 #include <stdlib.h>
 #include <stdlib.h>
 
 

+ 4 - 5
Userland/Applications/Browser/main.cpp

@@ -14,7 +14,6 @@
 #include <Applications/Browser/WindowActions.h>
 #include <Applications/Browser/WindowActions.h>
 #include <LibConfig/Client.h>
 #include <LibConfig/Client.h>
 #include <LibCore/ArgsParser.h>
 #include <LibCore/ArgsParser.h>
-#include <LibCore/DeprecatedFile.h>
 #include <LibCore/FileWatcher.h>
 #include <LibCore/FileWatcher.h>
 #include <LibCore/StandardPaths.h>
 #include <LibCore/StandardPaths.h>
 #include <LibCore/System.h>
 #include <LibCore/System.h>
@@ -131,16 +130,16 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
         }
         }
     }
     }
 
 
-    auto url_from_argument_string = [](DeprecatedString const& string) -> URL {
+    auto url_from_argument_string = [](DeprecatedString const& string) -> ErrorOr<URL> {
         if (FileSystem::exists(string)) {
         if (FileSystem::exists(string)) {
-            return URL::create_with_file_scheme(Core::DeprecatedFile::real_path_for(string));
+            return URL::create_with_file_scheme(TRY(FileSystem::real_path(string)).to_deprecated_string());
         }
         }
         return Browser::url_from_user_input(string);
         return Browser::url_from_user_input(string);
     };
     };
 
 
     URL first_url = Browser::url_from_user_input(Browser::g_home_url);
     URL first_url = Browser::url_from_user_input(Browser::g_home_url);
     if (!specified_urls.is_empty())
     if (!specified_urls.is_empty())
-        first_url = url_from_argument_string(specified_urls.first());
+        first_url = TRY(url_from_argument_string(specified_urls.first()));
 
 
     auto cookie_jar = TRY(Browser::CookieJar::create(*database));
     auto cookie_jar = TRY(Browser::CookieJar::create(*database));
     auto window = Browser::BrowserWindow::construct(cookie_jar, first_url);
     auto window = Browser::BrowserWindow::construct(cookie_jar, first_url);
@@ -176,7 +175,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
     };
     };
 
 
     for (size_t i = 1; i < specified_urls.size(); ++i)
     for (size_t i = 1; i < specified_urls.size(); ++i)
-        window->create_new_tab(url_from_argument_string(specified_urls[i]), Web::HTML::ActivateTab::No);
+        window->create_new_tab(TRY(url_from_argument_string(specified_urls[i])), Web::HTML::ActivateTab::No);
 
 
     window->show();
     window->show();
 
 

+ 1 - 1
Userland/Applications/Escalator/CMakeLists.txt

@@ -16,4 +16,4 @@ set(GENERATED_SOURCES
 )
 )
 
 
 serenity_app(Escalator ICON app-escalator)
 serenity_app(Escalator ICON app-escalator)
-target_link_libraries(Escalator PRIVATE LibCore LibDesktop LibGfx LibGUI LibMain)
+target_link_libraries(Escalator PRIVATE LibCore LibFileSystem LibDesktop LibGfx LibGUI LibMain)

+ 3 - 3
Userland/Applications/Escalator/main.cpp

@@ -9,8 +9,8 @@
 #include <AK/DeprecatedString.h>
 #include <AK/DeprecatedString.h>
 #include <LibCore/Account.h>
 #include <LibCore/Account.h>
 #include <LibCore/ArgsParser.h>
 #include <LibCore/ArgsParser.h>
-#include <LibCore/DeprecatedFile.h>
 #include <LibCore/System.h>
 #include <LibCore/System.h>
+#include <LibFileSystem/FileSystem.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Desktop.h>
 #include <LibGUI/Desktop.h>
 #include <LibGUI/MessageBox.h>
 #include <LibGUI/MessageBox.h>
@@ -33,8 +33,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
 
 
     auto app = TRY(GUI::Application::try_create(arguments));
     auto app = TRY(GUI::Application::try_create(arguments));
 
 
-    auto executable_path = Core::DeprecatedFile::resolve_executable_from_environment(command[0]);
-    if (!executable_path.has_value()) {
+    auto executable_path = FileSystem::resolve_executable_from_environment(command[0]);
+    if (executable_path.is_error()) {
         GUI::MessageBox::show_error(nullptr, DeprecatedString::formatted("Could not execute command {}: Command not found.", command[0]));
         GUI::MessageBox::show_error(nullptr, DeprecatedString::formatted("Could not execute command {}: Command not found.", command[0]));
         return 127;
         return 127;
     }
     }

+ 8 - 6
Userland/Applications/FileManager/DirectoryView.cpp

@@ -11,7 +11,6 @@
 #include <AK/NumberFormat.h>
 #include <AK/NumberFormat.h>
 #include <AK/StringBuilder.h>
 #include <AK/StringBuilder.h>
 #include <LibConfig/Client.h>
 #include <LibConfig/Client.h>
-#include <LibCore/DeprecatedFile.h>
 #include <LibCore/MimeData.h>
 #include <LibCore/MimeData.h>
 #include <LibCore/StandardPaths.h>
 #include <LibCore/StandardPaths.h>
 #include <LibFileSystem/FileSystem.h>
 #include <LibFileSystem/FileSystem.h>
@@ -406,18 +405,21 @@ void DirectoryView::add_path_to_history(DeprecatedString path)
 
 
 bool DirectoryView::open(DeprecatedString const& path)
 bool DirectoryView::open(DeprecatedString const& path)
 {
 {
-    auto real_path = Core::DeprecatedFile::real_path_for(path);
-    if (real_path.is_null() || !FileSystem::is_directory(path))
+    auto error_or_real_path = FileSystem::real_path(path);
+    if (error_or_real_path.is_error() || !FileSystem::is_directory(path))
         return false;
         return false;
 
 
-    if (chdir(real_path.characters()) < 0) {
+    auto real_path = error_or_real_path.release_value();
+    if (Core::System::chdir(real_path).is_error()) {
         perror("chdir");
         perror("chdir");
+        return false;
     }
     }
-    if (model().root_path() == real_path) {
+
+    if (model().root_path() == real_path.to_deprecated_string()) {
         refresh();
         refresh();
     } else {
     } else {
         set_active_widget(&current_view());
         set_active_widget(&current_view());
-        model().set_root_path(real_path);
+        model().set_root_path(real_path.to_deprecated_string());
     }
     }
     return true;
     return true;
 }
 }

+ 2 - 3
Userland/Applications/FileManager/PropertiesWindow.cpp

@@ -10,7 +10,6 @@
 #include <AK/NumberFormat.h>
 #include <AK/NumberFormat.h>
 #include <Applications/FileManager/DirectoryView.h>
 #include <Applications/FileManager/DirectoryView.h>
 #include <Applications/FileManager/PropertiesWindowGeneralTabGML.h>
 #include <Applications/FileManager/PropertiesWindowGeneralTabGML.h>
-#include <LibCore/DeprecatedFile.h>
 #include <LibCore/Directory.h>
 #include <LibCore/Directory.h>
 #include <LibCore/System.h>
 #include <LibCore/System.h>
 #include <LibDesktop/Launcher.h>
 #include <LibDesktop/Launcher.h>
@@ -102,11 +101,11 @@ ErrorOr<void> PropertiesWindow::create_widgets(bool disable_rename)
     type->set_text(get_description(m_mode));
     type->set_text(get_description(m_mode));
 
 
     if (S_ISLNK(m_mode)) {
     if (S_ISLNK(m_mode)) {
-        auto link_destination_or_error = Core::DeprecatedFile::read_link(m_path);
+        auto link_destination_or_error = FileSystem::read_link(m_path);
         if (link_destination_or_error.is_error()) {
         if (link_destination_or_error.is_error()) {
             perror("readlink");
             perror("readlink");
         } else {
         } else {
-            auto link_destination = link_destination_or_error.release_value();
+            auto link_destination = link_destination_or_error.release_value().to_deprecated_string();
             auto* link_location = general_tab->find_descendant_of_type_named<GUI::LinkLabel>("link_location");
             auto* link_location = general_tab->find_descendant_of_type_named<GUI::LinkLabel>("link_location");
             link_location->set_text(link_destination);
             link_location->set_text(link_destination);
             link_location->on_click = [link_destination] {
             link_location->on_click = [link_destination] {

+ 4 - 5
Userland/Applications/FileManager/main.cpp

@@ -19,7 +19,6 @@
 #include <LibConfig/Client.h>
 #include <LibConfig/Client.h>
 #include <LibConfig/Listener.h>
 #include <LibConfig/Listener.h>
 #include <LibCore/ArgsParser.h>
 #include <LibCore/ArgsParser.h>
-#include <LibCore/DeprecatedFile.h>
 #include <LibCore/Process.h>
 #include <LibCore/Process.h>
 #include <LibCore/StandardPaths.h>
 #include <LibCore/StandardPaths.h>
 #include <LibCore/System.h>
 #include <LibCore/System.h>
@@ -109,8 +108,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
 
 
     LexicalPath path(initial_location);
     LexicalPath path(initial_location);
     if (!initial_location.is_empty()) {
     if (!initial_location.is_empty()) {
-        if (!ignore_path_resolution)
-            initial_location = Core::DeprecatedFile::real_path_for(initial_location);
+        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_deprecated_string();
 
 
         if (!FileSystem::is_directory(initial_location)) {
         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
             // We want to extract zips to a temporary directory when FileManager is launched with a .zip file as its first argument
@@ -142,8 +141,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
         }
         }
     }
     }
 
 
-    if (initial_location.is_empty())
-        initial_location = Core::DeprecatedFile::current_working_directory();
+    if (auto error_or_cwd = FileSystem::current_working_directory(); initial_location.is_empty() && !error_or_cwd.is_error())
+        initial_location = error_or_cwd.release_value().to_deprecated_string();
 
 
     if (initial_location.is_empty())
     if (initial_location.is_empty())
         initial_location = Core::StandardPaths::home_directory();
         initial_location = Core::StandardPaths::home_directory();

+ 0 - 1
Userland/Applications/ImageViewer/ViewWidget.cpp

@@ -12,7 +12,6 @@
 #include "ViewWidget.h"
 #include "ViewWidget.h"
 #include <AK/LexicalPath.h>
 #include <AK/LexicalPath.h>
 #include <AK/StringBuilder.h>
 #include <AK/StringBuilder.h>
-#include <LibCore/DeprecatedFile.h>
 #include <LibCore/Directory.h>
 #include <LibCore/Directory.h>
 #include <LibCore/MappedFile.h>
 #include <LibCore/MappedFile.h>
 #include <LibCore/MimeData.h>
 #include <LibCore/MimeData.h>

+ 1 - 1
Userland/Applications/Run/CMakeLists.txt

@@ -16,4 +16,4 @@ set(GENERATED_SOURCES
 )
 )
 
 
 serenity_app(Run ICON app-run)
 serenity_app(Run ICON app-run)
-target_link_libraries(Run PRIVATE LibCore LibDesktop LibGfx LibGUI LibMain)
+target_link_libraries(Run PRIVATE LibCore LibFileSystem LibDesktop LibGfx LibGUI LibMain)

+ 5 - 6
Userland/Applications/Run/RunWindow.cpp

@@ -9,9 +9,9 @@
 #include <AK/LexicalPath.h>
 #include <AK/LexicalPath.h>
 #include <AK/URL.h>
 #include <AK/URL.h>
 #include <Applications/Run/RunGML.h>
 #include <Applications/Run/RunGML.h>
-#include <LibCore/DeprecatedFile.h>
 #include <LibCore/StandardPaths.h>
 #include <LibCore/StandardPaths.h>
 #include <LibDesktop/Launcher.h>
 #include <LibDesktop/Launcher.h>
+#include <LibFileSystem/FileSystem.h>
 #include <LibGUI/Button.h>
 #include <LibGUI/Button.h>
 #include <LibGUI/Event.h>
 #include <LibGUI/Event.h>
 #include <LibGUI/FilePicker.h>
 #include <LibGUI/FilePicker.h>
@@ -142,13 +142,12 @@ bool RunWindow::run_via_launch(DeprecatedString const& run_input)
     auto url = URL::create_with_url_or_path(run_input);
     auto url = URL::create_with_url_or_path(run_input);
 
 
     if (url.scheme() == "file") {
     if (url.scheme() == "file") {
-        auto real_path = Core::DeprecatedFile::real_path_for(url.path());
-        if (real_path.is_null()) {
-            // errno *should* be preserved from Core::DeprecatedFile::real_path_for().
-            warnln("Failed to launch '{}': {}", url.path(), strerror(errno));
+        auto real_path_or_error = FileSystem::real_path(url.path());
+        if (real_path_or_error.is_error()) {
+            warnln("Failed to launch '{}': {}", url.path(), real_path_or_error.error());
             return false;
             return false;
         }
         }
-        url = URL::create_with_url_or_path(real_path);
+        url = URL::create_with_url_or_path(real_path_or_error.release_value().to_deprecated_string());
     }
     }
 
 
     if (!Desktop::Launcher::open(url)) {
     if (!Desktop::Launcher::open(url)) {

+ 1 - 1
Userland/Applications/SpaceAnalyzer/main.cpp

@@ -147,7 +147,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
                 if (tree_map_widget.viewpoint() == 0)
                 if (tree_map_widget.viewpoint() == 0)
                     window->set_title("/ - SpaceAnalyzer");
                     window->set_title("/ - SpaceAnalyzer");
 
 
-                breadcrumbbar.append_segment("/", GUI::FileIconProvider::icon_for_path("/").bitmap_for_size(16), "/", "/");
+                breadcrumbbar.append_segment("/", GUI::FileIconProvider::icon_for_path("/"sv).bitmap_for_size(16), "/", "/");
                 continue;
                 continue;
             }
             }
 
 

+ 1 - 1
Userland/Applications/Terminal/CMakeLists.txt

@@ -9,4 +9,4 @@ set(SOURCES
 )
 )
 
 
 serenity_app(Terminal ICON app-terminal)
 serenity_app(Terminal ICON app-terminal)
-target_link_libraries(Terminal PRIVATE LibConfig LibCore LibDesktop LibGfx LibGUI LibVT LibMain)
+target_link_libraries(Terminal PRIVATE LibConfig LibCore LibFileSystem LibDesktop LibGfx LibGUI LibVT LibMain)

+ 1 - 1
Userland/Applications/Terminal/main.cpp

@@ -10,10 +10,10 @@
 #include <LibConfig/Client.h>
 #include <LibConfig/Client.h>
 #include <LibConfig/Listener.h>
 #include <LibConfig/Listener.h>
 #include <LibCore/ArgsParser.h>
 #include <LibCore/ArgsParser.h>
-#include <LibCore/DeprecatedFile.h>
 #include <LibCore/DirIterator.h>
 #include <LibCore/DirIterator.h>
 #include <LibCore/System.h>
 #include <LibCore/System.h>
 #include <LibDesktop/Launcher.h>
 #include <LibDesktop/Launcher.h>
+#include <LibFileSystem/FileSystem.h>
 #include <LibGUI/Action.h>
 #include <LibGUI/Action.h>
 #include <LibGUI/ActionGroup.h>
 #include <LibGUI/ActionGroup.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Application.h>

+ 5 - 5
Userland/Applications/ThemeEditor/main.cpp

@@ -10,8 +10,8 @@
 
 
 #include "MainWidget.h"
 #include "MainWidget.h"
 #include <LibCore/ArgsParser.h>
 #include <LibCore/ArgsParser.h>
-#include <LibCore/DeprecatedFile.h>
 #include <LibCore/System.h>
 #include <LibCore/System.h>
+#include <LibFileSystem/FileSystem.h>
 #include <LibFileSystemAccessClient/Client.h>
 #include <LibFileSystemAccessClient/Client.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Application.h>
 #include <LibGUI/Icon.h>
 #include <LibGUI/Icon.h>
@@ -33,10 +33,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
     parser.add_positional_argument(file_to_edit, "Theme file to edit", "file", Core::ArgsParser::Required::No);
     parser.add_positional_argument(file_to_edit, "Theme file to edit", "file", Core::ArgsParser::Required::No);
     parser.parse(arguments);
     parser.parse(arguments);
 
 
-    Optional<DeprecatedString> path = {};
+    Optional<String> path = {};
 
 
-    if (!file_to_edit.is_empty())
-        path = Core::DeprecatedFile::absolute_path(file_to_edit);
+    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();
 
 
     TRY(Core::System::pledge("stdio recvfd sendfd thread rpath unix"));
     TRY(Core::System::pledge("stdio recvfd sendfd thread rpath unix"));
     TRY(Core::System::unveil("/tmp/session/%sid/portal/filesystemaccess", "rw"));
     TRY(Core::System::unveil("/tmp/session/%sid/portal/filesystemaccess", "rw"));
@@ -52,7 +52,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
         // Note: This is deferred to ensure that the window has already popped and thus proper window stealing can be performed.
         // Note: This is deferred to ensure that the window has already popped and thus proper window stealing can be performed.
         app->event_loop().deferred_invoke(
         app->event_loop().deferred_invoke(
             [&window, &path, &main_widget]() {
             [&window, &path, &main_widget]() {
-                auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, path.value());
+                auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, path.value().to_deprecated_string());
                 if (response.is_error())
                 if (response.is_error())
                     GUI::MessageBox::show_error(window, DeprecatedString::formatted("Opening \"{}\" failed: {}", path.value(), response.error()));
                     GUI::MessageBox::show_error(window, DeprecatedString::formatted("Opening \"{}\" failed: {}", path.value(), response.error()));
                 else {
                 else {