1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:07:34 +00:00

FileManager+HackStudio+SpaceAnalyzer: Use File::can_delete_or_move

This commit is contained in:
Karol Kosek 2021-10-09 18:13:43 +02:00 committed by Linus Groh
parent b810f7f88a
commit e45434c0c7
3 changed files with 3 additions and 13 deletions

View file

@ -555,7 +555,7 @@ bool DirectoryView::can_modify_current_selection()
// FIXME: remove once Clang formats this properly. // FIXME: remove once Clang formats this properly.
// clang-format off // clang-format off
return selections.first_matching([&](auto& index) { return selections.first_matching([&](auto& index) {
return !Core::System::access(node(index.parent()).full_path(), W_OK).is_error(); return Core::File::can_delete_or_move(node(index).full_path());
}).has_value(); }).has_value();
// clang-format on // clang-format on
} }

View file

@ -31,7 +31,6 @@
#include <LibGUI/Statusbar.h> #include <LibGUI/Statusbar.h>
#include <LibGfx/Bitmap.h> #include <LibGfx/Bitmap.h>
#include <LibMain/Main.h> #include <LibMain/Main.h>
#include <unistd.h>
static constexpr auto APP_NAME = "Space Analyzer"sv; static constexpr auto APP_NAME = "Space Analyzer"sv;
@ -137,15 +136,6 @@ static ErrorOr<void> analyze(RefPtr<Tree> tree, SpaceAnalyzer::TreeMapWidget& tr
return {}; return {};
} }
static bool is_removable(DeprecatedString const& absolute_path)
{
VERIFY(!absolute_path.is_empty());
int access_result = access(LexicalPath::dirname(absolute_path).characters(), W_OK);
if (access_result != 0 && errno != EACCES)
perror("access");
return access_result == 0;
}
static DeprecatedString get_absolute_path_to_selected_node(SpaceAnalyzer::TreeMapWidget const& treemapwidget, bool include_last_node = true) static DeprecatedString get_absolute_path_to_selected_node(SpaceAnalyzer::TreeMapWidget const& treemapwidget, bool include_last_node = true)
{ {
StringBuilder path_builder; StringBuilder path_builder;
@ -288,7 +278,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
DeprecatedString selected_node_path = get_absolute_path_to_selected_node(treemapwidget); DeprecatedString selected_node_path = get_absolute_path_to_selected_node(treemapwidget);
if (selected_node_path.is_empty()) if (selected_node_path.is_empty())
return; return;
delete_action->set_enabled(is_removable(selected_node_path)); delete_action->set_enabled(Core::File::can_delete_or_move(selected_node_path));
if (Core::File::is_directory(selected_node_path)) { if (Core::File::is_directory(selected_node_path)) {
open_folder_action->set_visible(true); open_folder_action->set_visible(true);
open_containing_folder_action->set_visible(false); open_containing_folder_action->set_visible(false);

View file

@ -1245,7 +1245,7 @@ void HackStudioWidget::configure_project_tree_view()
auto selections = m_project_tree_view->selection().indices(); auto selections = m_project_tree_view->selection().indices();
auto it = selections.find_if([&](auto selected_file) { auto it = selections.find_if([&](auto selected_file) {
return access(m_project->model().full_path(selected_file.parent()).characters(), W_OK) == 0; return Core::File::can_delete_or_move(m_project->model().full_path(selected_file));
}); });
bool has_permissions = it != selections.end(); bool has_permissions = it != selections.end();
m_tree_view_rename_action->set_enabled(has_permissions); m_tree_view_rename_action->set_enabled(has_permissions);