mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-21 18:37:58 +03:00
Applications: Convert DeprecatedFile
usages to LibFileSystem
This commit is contained in:
parent
5ba7449342
commit
1dc3ba6ed5
Notes:
sideshowbarker
2024-07-16 22:54:10 +09:00
Author: https://github.com/cammo1123 Commit: https://github.com/SerenityOS/serenity/commit/1dc3ba6ed5 Pull-request: https://github.com/SerenityOS/serenity/pull/17985 Reviewed-by: https://github.com/linusg
@ -9,7 +9,6 @@
|
||||
#include "WavefrontOBJLoader.h"
|
||||
#include <AK/FixedArray.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibCore/DeprecatedFile.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include <Applications/Browser/WindowActions.h>
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/DeprecatedFile.h>
|
||||
#include <LibCore/FileWatcher.h>
|
||||
#include <LibCore/StandardPaths.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)) {
|
||||
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);
|
||||
};
|
||||
|
||||
URL first_url = Browser::url_from_user_input(Browser::g_home_url);
|
||||
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 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)
|
||||
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();
|
||||
|
||||
|
@ -16,4 +16,4 @@ set(GENERATED_SOURCES
|
||||
)
|
||||
|
||||
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)
|
||||
|
@ -9,8 +9,8 @@
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <LibCore/Account.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/DeprecatedFile.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibFileSystem/FileSystem.h>
|
||||
#include <LibGUI/Application.h>
|
||||
#include <LibGUI/Desktop.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 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]));
|
||||
return 127;
|
||||
}
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include <AK/NumberFormat.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibCore/DeprecatedFile.h>
|
||||
#include <LibCore/MimeData.h>
|
||||
#include <LibCore/StandardPaths.h>
|
||||
#include <LibFileSystem/FileSystem.h>
|
||||
@ -406,18 +405,21 @@ void DirectoryView::add_path_to_history(DeprecatedString 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;
|
||||
|
||||
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");
|
||||
return false;
|
||||
}
|
||||
if (model().root_path() == real_path) {
|
||||
|
||||
if (model().root_path() == real_path.to_deprecated_string()) {
|
||||
refresh();
|
||||
} else {
|
||||
set_active_widget(¤t_view());
|
||||
model().set_root_path(real_path);
|
||||
model().set_root_path(real_path.to_deprecated_string());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include <AK/NumberFormat.h>
|
||||
#include <Applications/FileManager/DirectoryView.h>
|
||||
#include <Applications/FileManager/PropertiesWindowGeneralTabGML.h>
|
||||
#include <LibCore/DeprecatedFile.h>
|
||||
#include <LibCore/Directory.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibDesktop/Launcher.h>
|
||||
@ -102,11 +101,11 @@ ErrorOr<void> PropertiesWindow::create_widgets(bool disable_rename)
|
||||
type->set_text(get_description(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()) {
|
||||
perror("readlink");
|
||||
} 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");
|
||||
link_location->set_text(link_destination);
|
||||
link_location->on_click = [link_destination] {
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibConfig/Listener.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/DeprecatedFile.h>
|
||||
#include <LibCore/Process.h>
|
||||
#include <LibCore/StandardPaths.h>
|
||||
#include <LibCore/System.h>
|
||||
@ -109,8 +108,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
|
||||
LexicalPath path(initial_location);
|
||||
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)) {
|
||||
// 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())
|
||||
initial_location = Core::StandardPaths::home_directory();
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "ViewWidget.h"
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibCore/DeprecatedFile.h>
|
||||
#include <LibCore/Directory.h>
|
||||
#include <LibCore/MappedFile.h>
|
||||
#include <LibCore/MimeData.h>
|
||||
|
@ -16,4 +16,4 @@ set(GENERATED_SOURCES
|
||||
)
|
||||
|
||||
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)
|
||||
|
@ -9,9 +9,9 @@
|
||||
#include <AK/LexicalPath.h>
|
||||
#include <AK/URL.h>
|
||||
#include <Applications/Run/RunGML.h>
|
||||
#include <LibCore/DeprecatedFile.h>
|
||||
#include <LibCore/StandardPaths.h>
|
||||
#include <LibDesktop/Launcher.h>
|
||||
#include <LibFileSystem/FileSystem.h>
|
||||
#include <LibGUI/Button.h>
|
||||
#include <LibGUI/Event.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);
|
||||
|
||||
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;
|
||||
}
|
||||
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)) {
|
||||
|
@ -147,7 +147,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
if (tree_map_widget.viewpoint() == 0)
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -9,4 +9,4 @@ set(SOURCES
|
||||
)
|
||||
|
||||
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)
|
||||
|
@ -10,10 +10,10 @@
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibConfig/Listener.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/DeprecatedFile.h>
|
||||
#include <LibCore/DirIterator.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibDesktop/Launcher.h>
|
||||
#include <LibFileSystem/FileSystem.h>
|
||||
#include <LibGUI/Action.h>
|
||||
#include <LibGUI/ActionGroup.h>
|
||||
#include <LibGUI/Application.h>
|
||||
|
@ -10,8 +10,8 @@
|
||||
|
||||
#include "MainWidget.h"
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/DeprecatedFile.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibFileSystem/FileSystem.h>
|
||||
#include <LibFileSystemAccessClient/Client.h>
|
||||
#include <LibGUI/Application.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.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::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.
|
||||
app->event_loop().deferred_invoke(
|
||||
[&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())
|
||||
GUI::MessageBox::show_error(window, DeprecatedString::formatted("Opening \"{}\" failed: {}", path.value(), response.error()));
|
||||
else {
|
||||
|
Loading…
Reference in New Issue
Block a user