1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:17:44 +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

@ -31,7 +31,6 @@
#include <LibGUI/Statusbar.h>
#include <LibGfx/Bitmap.h>
#include <LibMain/Main.h>
#include <unistd.h>
static constexpr auto APP_NAME = "Space Analyzer"sv;
@ -137,15 +136,6 @@ static ErrorOr<void> analyze(RefPtr<Tree> tree, SpaceAnalyzer::TreeMapWidget& tr
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)
{
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);
if (selected_node_path.is_empty())
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)) {
open_folder_action->set_visible(true);
open_containing_folder_action->set_visible(false);