From ee7c8fbd7b551ebd5085ee6f3705bce2684cef2b Mon Sep 17 00:00:00 2001 From: Bui Quang Minh Date: Tue, 2 Mar 2021 12:18:59 +0700 Subject: [PATCH] HackStudio: Implement removing file from disk --- .../DevTools/HackStudio/HackStudioWidget.cpp | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp index 9543ba77a4..391c543967 100644 --- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp +++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp @@ -376,15 +376,32 @@ NonnullRefPtr HackStudioWidget::create_delete_action() return; for (auto& file : files) { - if (1) { - // FIXME: Remove `file` from disk - } else { + struct stat st; + if (lstat(file.characters(), &st) < 0) { GUI::MessageBox::show(window(), - String::formatted("Removing file {} from the project failed.", file), + String::formatted("lstat ({}) failed: {}", file, strerror(errno)), "Removal failed", GUI::MessageBox::Type::Error); break; } + + bool is_directory = S_ISDIR(st.st_mode); + auto result = Core::File::remove(file, Core::File::RecursionMode::Allowed, false); + if (result.is_error()) { + auto& error = result.error(); + if (is_directory) { + GUI::MessageBox::show(window(), + String::formatted("Removing directory {} from the project failed: {}", error.file, error.error_code), + "Removal failed", + GUI::MessageBox::Type::Error); + } else { + GUI::MessageBox::show(window(), + String::formatted("Removing file {} from the project failed: {}", error.file, error.error_code), + "Removal failed", + GUI::MessageBox::Type::Error); + } + break; + } } }); delete_action->set_enabled(false);