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

Everywhere: Use LibFileSystem where trivial

This commit is contained in:
Cameron Youell 2023-03-22 02:35:30 +11:00 committed by Linus Groh
parent edab0cbf41
commit 1d24f394c6
115 changed files with 275 additions and 228 deletions

View file

@ -41,5 +41,5 @@ set(GENERATED_SOURCES
)
serenity_app(Browser ICON app-browser)
target_link_libraries(Browser PRIVATE LibCore LibWebView LibWeb LibProtocol LibGUI LibDesktop LibConfig LibGfx LibIPC LibJS LibLocale LibMain LibSyntax LibSQL)
target_link_libraries(Browser PRIVATE LibCore LibFileSystem LibWebView LibWeb LibProtocol LibGUI LibDesktop LibConfig LibGfx LibIPC LibJS LibLocale LibMain LibSyntax LibSQL)
link_with_locale_data(Browser)

View file

@ -19,6 +19,7 @@
#include <LibCore/StandardPaths.h>
#include <LibCore/System.h>
#include <LibDesktop/Launcher.h>
#include <LibFileSystem/FileSystem.h>
#include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Icon.h>
@ -131,7 +132,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}
auto url_from_argument_string = [](DeprecatedString const& string) -> URL {
if (Core::DeprecatedFile::exists(string)) {
if (FileSystem::exists(string)) {
return URL::create_with_file_scheme(Core::DeprecatedFile::real_path_for(string));
}
return Browser::url_from_user_input(string);

View file

@ -16,4 +16,4 @@ set(GENERATED_SOURCES
)
serenity_app(CrashReporter ICON app-crash-reporter)
target_link_libraries(CrashReporter PRIVATE LibCore LibCoredump LibDebug LibDesktop LibFileSystemAccessClient LibGfx LibGUI LibMain LibThreading)
target_link_libraries(CrashReporter PRIVATE LibCore LibCoredump LibDebug LibDesktop LibFileSystem LibFileSystemAccessClient LibGfx LibGUI LibMain LibThreading)

View file

@ -12,13 +12,13 @@
#include <AK/URL.h>
#include <Applications/CrashReporter/CrashReporterWindowGML.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/DeprecatedFile.h>
#include <LibCore/System.h>
#include <LibCoredump/Backtrace.h>
#include <LibCoredump/Reader.h>
#include <LibDesktop/AppFile.h>
#include <LibDesktop/Launcher.h>
#include <LibELF/Core.h>
#include <LibFileSystem/FileSystem.h>
#include <LibFileSystemAccessClient/Client.h>
#include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h>
@ -131,7 +131,7 @@ static TitleAndText build_cpu_registers(const ELF::Core::ThreadInfo& thread_info
static void unlink_coredump(StringView coredump_path)
{
if (Core::DeprecatedFile::remove(coredump_path, Core::DeprecatedFile::RecursionMode::Disallowed).is_error())
if (FileSystem::remove(coredump_path, FileSystem::RecursionMode::Disallowed).is_error())
dbgln("Failed deleting coredump file");
}

View file

@ -25,4 +25,4 @@ set(GENERATED_SOURCES
)
serenity_app(FileManager ICON app-file-manager)
target_link_libraries(FileManager PRIVATE LibCore LibGfx LibGUI LibDesktop LibConfig LibMain LibThreading)
target_link_libraries(FileManager PRIVATE LibCore LibFileSystem LibGfx LibGUI LibDesktop LibConfig LibMain LibThreading)

View file

@ -14,6 +14,7 @@
#include <LibCore/DeprecatedFile.h>
#include <LibCore/MimeData.h>
#include <LibCore/StandardPaths.h>
#include <LibFileSystem/FileSystem.h>
#include <LibGUI/FileIconProvider.h>
#include <LibGUI/InputBox.h>
#include <LibGUI/Label.h>
@ -204,7 +205,7 @@ void DirectoryView::setup_model()
while (model_root.string() != "/") {
model_root = model_root.parent();
if (Core::DeprecatedFile::is_directory(model_root.string()))
if (FileSystem::is_directory(model_root.string()))
break;
}
@ -406,7 +407,7 @@ 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() || !Core::DeprecatedFile::is_directory(path))
if (real_path.is_null() || !FileSystem::is_directory(path))
return false;
if (chdir(real_path.characters()) < 0) {
@ -555,7 +556,7 @@ bool DirectoryView::can_modify_current_selection()
// FIXME: remove once Clang formats this properly.
// clang-format off
return selections.first_matching([&](auto& index) {
return Core::DeprecatedFile::can_delete_or_move(node(index).full_path());
return FileSystem::can_delete_or_move(node(index).full_path());
}).has_value();
// clang-format on
}

View file

@ -8,9 +8,9 @@
#include "FileUtils.h"
#include "FileOperationProgressWidget.h"
#include <AK/LexicalPath.h>
#include <LibCore/DeprecatedFile.h>
#include <LibCore/MimeData.h>
#include <LibCore/System.h>
#include <LibFileSystem/FileSystem.h>
#include <LibGUI/Event.h>
#include <LibGUI/MessageBox.h>
#include <unistd.h>
@ -124,7 +124,7 @@ ErrorOr<bool> handle_drop(GUI::DropEvent const& event, DeprecatedString const& d
auto const target = LexicalPath::canonicalized_path(destination);
if (!Core::DeprecatedFile::is_directory(target))
if (!FileSystem::is_directory(target))
return has_accepted_drop;
Vector<DeprecatedString> paths_to_copy;

View file

@ -14,6 +14,7 @@
#include <LibCore/Directory.h>
#include <LibCore/System.h>
#include <LibDesktop/Launcher.h>
#include <LibFileSystem/FileSystem.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/CheckBox.h>
#include <LibGUI/FileIconProvider.h>
@ -212,7 +213,7 @@ bool PropertiesWindow::apply_changes()
DeprecatedString new_name = m_name_box->text();
DeprecatedString new_file = make_full_path(new_name).characters();
if (Core::DeprecatedFile::exists(new_file)) {
if (FileSystem::exists(new_file)) {
GUI::MessageBox::show(this, DeprecatedString::formatted("A file \"{}\" already exists!", new_name), "Error"sv, GUI::MessageBox::Type::Error);
return false;
}

View file

@ -25,6 +25,7 @@
#include <LibCore/System.h>
#include <LibCore/TempFile.h>
#include <LibDesktop/Launcher.h>
#include <LibFileSystem/FileSystem.h>
#include <LibGUI/Action.h>
#include <LibGUI/ActionGroup.h>
#include <LibGUI/Application.h>
@ -111,7 +112,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (!ignore_path_resolution)
initial_location = Core::DeprecatedFile::real_path_for(initial_location);
if (!Core::DeprecatedFile::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
if (path.has_extension(".zip"sv)) {
auto temp_directory = Core::TempFile::create_temp_directory();
@ -215,7 +216,7 @@ void do_create_link(Vector<DeprecatedString> const& selected_file_paths, GUI::Wi
{
auto path = selected_file_paths.first();
auto destination = DeprecatedString::formatted("{}/{}", Core::StandardPaths::desktop_directory(), LexicalPath::basename(path));
if (auto result = Core::DeprecatedFile::link_file(destination, path); result.is_error()) {
if (auto result = FileSystem::link_file(destination, path); result.is_error()) {
GUI::MessageBox::show(window, DeprecatedString::formatted("Could not create desktop shortcut:\n{}", result.error()), "File Manager"sv,
GUI::MessageBox::Type::Error);
}
@ -483,7 +484,7 @@ ErrorOr<int> run_in_desktop_mode()
}
for (auto& path : paths) {
if (Core::DeprecatedFile::is_directory(path))
if (FileSystem::is_directory(path))
Desktop::Launcher::open(URL::create_with_file_scheme(path));
}
});
@ -496,7 +497,7 @@ ErrorOr<int> run_in_desktop_mode()
}
for (auto& path : paths) {
if (Core::DeprecatedFile::is_directory(path)) {
if (FileSystem::is_directory(path)) {
spawn_terminal(path);
}
}
@ -821,7 +822,7 @@ ErrorOr<int> run_in_windowed_mode(DeprecatedString const& initial_location, Depr
paths = directory_view->selected_file_paths();
for (auto& path : paths) {
if (Core::DeprecatedFile::is_directory(path))
if (FileSystem::is_directory(path))
Desktop::Launcher::open(URL::create_with_file_scheme(path));
}
},
@ -840,7 +841,7 @@ ErrorOr<int> run_in_windowed_mode(DeprecatedString const& initial_location, Depr
paths = directory_view->selected_file_paths();
for (auto& path : paths) {
if (Core::DeprecatedFile::is_directory(path)) {
if (FileSystem::is_directory(path)) {
spawn_terminal(path);
}
}
@ -1092,7 +1093,7 @@ ErrorOr<int> run_in_windowed_mode(DeprecatedString const& initial_location, Depr
(void)TRY(main_toolbar.try_add_action(directory_view->view_as_columns_action()));
breadcrumbbar.on_path_change = [&](auto selected_path) {
if (Core::DeprecatedFile::is_directory(selected_path)) {
if (FileSystem::is_directory(selected_path)) {
directory_view->open(selected_path);
} else {
dbgln("Breadcrumb path '{}' doesn't exist", selected_path);

View file

@ -15,4 +15,4 @@ set(GENERATED_SOURCES
)
serenity_app(PartitionEditor ICON app-partition-editor)
target_link_libraries(PartitionEditor PRIVATE LibCore LibGfx LibMain LibGUI LibPartition)
target_link_libraries(PartitionEditor PRIVATE LibCore LibFileSystem LibGfx LibMain LibGUI LibPartition)

View file

@ -13,6 +13,11 @@
namespace PartitionEditor {
NonnullRefPtr<PartitionModel> PartitionModel::create()
{
return adopt_ref(*new PartitionModel);
}
DeprecatedString PartitionModel::column_name(int column) const
{
switch (column) {

View file

@ -22,7 +22,7 @@ public:
__Count,
};
static NonnullRefPtr<PartitionModel> create() { return adopt_ref(*new PartitionModel()); }
static NonnullRefPtr<PartitionModel> create();
virtual ~PartitionModel() override = default;
virtual int row_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return m_partition_table->partitions_count(); }

View file

@ -6,9 +6,9 @@
#include <Applications/PartitionEditor/PartitionEditorWindowGML.h>
#include <Applications/PartitionEditor/PartitionModel.h>
#include <LibCore/DeprecatedFile.h>
#include <LibCore/Directory.h>
#include <LibCore/System.h>
#include <LibFileSystem/FileSystem.h>
#include <LibGUI/Application.h>
#include <LibGUI/ComboBox.h>
#include <LibGUI/ItemListModel.h>
@ -23,7 +23,7 @@ static Vector<DeprecatedString> get_device_paths()
// FIXME: Propagate errors.
(void)Core::Directory::for_each_entry("/dev"sv, Core::DirIterator::Flags::SkipParentAndBaseDir, [&](auto const& entry, auto const& directory) -> ErrorOr<IterationDecision> {
auto full_path = LexicalPath::join(directory.path().string(), entry.name).string();
if (Core::DeprecatedFile::is_block_device(full_path))
if (FileSystem::is_block_device(full_path))
device_paths.append(full_path);
return IterationDecision::Continue;
});

View file

@ -8,7 +8,7 @@
#include "AlbumCoverVisualizationWidget.h"
#include <AK/LexicalPath.h>
#include <LibCore/DeprecatedFile.h>
#include <LibFileSystem/FileSystem.h>
#include <LibGUI/Painter.h>
#include <LibGfx/Rect.h>
@ -48,7 +48,7 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> AlbumCoverVisualizationWidget::get_album_cov
static constexpr auto possible_cover_filenames = Array { "cover.png"sv, "cover.jpg"sv };
for (auto& it : possible_cover_filenames) {
LexicalPath cover_path = LexicalPath::join(directory, it);
if (Core::DeprecatedFile::exists(cover_path.string()))
if (FileSystem::exists(cover_path.string()))
return Gfx::Bitmap::load_from_file(cover_path.string());
}

View file

@ -19,4 +19,4 @@ set(SOURCES
)
serenity_app(SoundPlayer ICON app-sound-player)
target_link_libraries(SoundPlayer PRIVATE LibAudio LibConfig LibCore LibDSP LibGfx LibGUI LibIPC LibMain LibThreading LibImageDecoderClient)
target_link_libraries(SoundPlayer PRIVATE LibAudio LibConfig LibCore LibFileSystem LibDSP LibGfx LibGUI LibIPC LibMain LibThreading LibImageDecoderClient)

View file

@ -7,7 +7,7 @@
#include "Player.h"
#include <LibAudio/FlacLoader.h>
#include <LibCore/DeprecatedFile.h>
#include <LibFileSystem/FileSystem.h>
Player::Player(Audio::ConnectionToServer& audio_client_connection)
: m_audio_client_connection(audio_client_connection)
@ -44,7 +44,7 @@ void Player::play_file_path(DeprecatedString const& path)
if (path.is_null())
return;
if (!Core::DeprecatedFile::exists(path)) {
if (!FileSystem::exists(path)) {
audio_load_error(path, "File does not exist"sv);
return;
}

View file

@ -10,7 +10,7 @@
#include <AK/LexicalPath.h>
#include <AK/Random.h>
#include <LibAudio/Loader.h>
#include <LibCore/DeprecatedFile.h>
#include <LibFileSystem/FileSystem.h>
#include <LibGUI/MessageBox.h>
bool Playlist::load(StringView path)
@ -39,11 +39,11 @@ void Playlist::try_fill_missing_info(Vector<M3UEntry>& entries, StringView path)
entry.path = DeprecatedString::formatted("{}/{}", playlist_path.dirname(), entry.path);
if (!entry.extended_info->file_size_in_bytes.has_value()) {
auto size = Core::DeprecatedFile::size(entry.path);
auto size = FileSystem::size(entry.path);
if (size.is_error())
continue;
entry.extended_info->file_size_in_bytes = size.value();
} else if (!Core::DeprecatedFile::exists(entry.path)) {
} else if (!FileSystem::exists(entry.path)) {
to_delete.append(&entry);
continue;
}

View file

@ -17,4 +17,4 @@ set(GENERATED_SOURCES
)
serenity_app(SpaceAnalyzer ICON app-space-analyzer)
target_link_libraries(SpaceAnalyzer PRIVATE LibCore LibDesktop LibGfx LibGUI LibIPC LibMain)
target_link_libraries(SpaceAnalyzer PRIVATE LibCore LibDesktop LibFileSystem LibGfx LibGUI LibIPC LibMain)

View file

@ -11,8 +11,8 @@
#include <AK/String.h>
#include <AK/URL.h>
#include <Applications/SpaceAnalyzer/SpaceAnalyzerGML.h>
#include <LibCore/DeprecatedFile.h>
#include <LibDesktop/Launcher.h>
#include <LibFileSystem/FileSystem.h>
#include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Breadcrumbbar.h>
@ -84,7 +84,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (path_string.is_empty())
return;
if (Core::DeprecatedFile::is_directory(path_string)) {
if (FileSystem::is_directory(path_string)) {
Desktop::Launcher::open(URL::create_with_file_scheme(path_string));
return;
}
@ -102,7 +102,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
while (try_again) {
try_again = false;
auto deletion_result = Core::DeprecatedFile::remove(selected_node_path, Core::DeprecatedFile::RecursionMode::Allowed);
auto deletion_result = FileSystem::remove(selected_node_path, FileSystem::RecursionMode::Allowed);
if (deletion_result.is_error()) {
auto retry_message_result = GUI::MessageBox::show(window,
DeprecatedString::formatted("Failed to delete \"{}\": {}. Retry?",
@ -168,8 +168,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
DeprecatedString selected_node_path = get_absolute_path_to_selected_node(tree_map_widget);
if (selected_node_path.is_empty())
return;
delete_action->set_enabled(Core::DeprecatedFile::can_delete_or_move(selected_node_path));
if (Core::DeprecatedFile::is_directory(selected_node_path))
delete_action->set_enabled(FileSystem::can_delete_or_move(selected_node_path));
if (FileSystem::is_directory(selected_node_path))
open_action->set_text("Open in File Manager");
else
open_action->set_text("Reveal in File Manager");

View file

@ -42,7 +42,7 @@ set(GENERATED_SOURCES
)
serenity_app(Spreadsheet ICON app-spreadsheet)
target_link_libraries(Spreadsheet PRIVATE LibCore LibFileSystemAccessClient LibGfx LibGUI LibJS LibMain LibMarkdown LibSyntax LibWebView LibWeb)
target_link_libraries(Spreadsheet PRIVATE LibCore LibFileSystem LibFileSystemAccessClient LibGfx LibGUI LibJS LibMain LibMarkdown LibSyntax LibWebView LibWeb)
serenity_test(Writers/Test/TestXSVWriter.cpp Spreadsheet)

View file

@ -10,8 +10,8 @@
#include <AK/ScopeGuard.h>
#include <AK/Try.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>
@ -34,7 +34,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.parse(arguments);
if (!filename.is_empty()) {
if (!Core::DeprecatedFile::exists(filename) || Core::DeprecatedFile::is_directory(filename)) {
if (!FileSystem::exists(filename) || FileSystem::is_directory(filename)) {
warnln("File does not exist or is a directory: {}", filename);
return 1;
}

View file

@ -28,4 +28,4 @@ set(GENERATED_SOURCES
)
serenity_app(ThemeEditor ICON app-theme-editor)
target_link_libraries(ThemeEditor PRIVATE LibCore LibGfx LibGUI LibFileSystemAccessClient LibIPC LibMain)
target_link_libraries(ThemeEditor PRIVATE LibCore LibGfx LibGUI LibFileSystem LibFileSystemAccessClient LibIPC LibMain)

View file

@ -15,7 +15,7 @@
#include <Applications/ThemeEditor/MetricPropertyGML.h>
#include <Applications/ThemeEditor/PathPropertyGML.h>
#include <Applications/ThemeEditor/ThemeEditorGML.h>
#include <LibCore/DeprecatedFile.h>
#include <LibFileSystem/FileSystem.h>
#include <LibFileSystemAccessClient/Client.h>
#include <LibGUI/ActionGroup.h>
#include <LibGUI/BoxLayout.h>
@ -591,8 +591,8 @@ void MainWidget::show_path_picker_dialog(StringView property_display_name, GUI::
bool open_folder = path_picker_target == PathPickerTarget::Folder;
auto window_title = DeprecatedString::formatted(open_folder ? "Select {} folder"sv : "Select {} file"sv, property_display_name);
auto target_path = path_input.text();
if (Core::DeprecatedFile::exists(target_path)) {
if (!Core::DeprecatedFile::is_directory(target_path))
if (FileSystem::exists(target_path)) {
if (!FileSystem::is_directory(target_path))
target_path = LexicalPath::dirname(target_path);
} else {
target_path = "/res/icons";