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

FileManager: Added support for deleting directories

Directories can now be deleted using the "Delete..." action from the
context menu
This commit is contained in:
Till Mayer 2019-11-21 21:43:02 +01:00 committed by Andreas Kling
parent 9009390f9c
commit 09189e34e3
3 changed files with 66 additions and 3 deletions

View file

@ -252,8 +252,33 @@ int main(int argc, char** argv)
return;
}
}
for (auto& path : paths) {
if (unlink(path.characters()) < 0) {
struct stat st;
if (lstat(path.characters(), &st)) {
GMessageBox::show(
String::format("lstat(%s) failed: %s", path.characters(), strerror(errno)),
"Delete failed",
GMessageBox::Type::Error,
GMessageBox::InputType::OK,
window);
break;
}
if (S_ISDIR(st.st_mode)) {
String error_path;
int error = FileUtils::delete_directory(path, error_path);
if (error) {
GMessageBox::show(
String::format("Failed to delete directory \"%s\": %s", error_path.characters(), strerror(error)),
"Delete failed",
GMessageBox::Type::Error,
GMessageBox::InputType::OK,
window);
break;
}
} else if (unlink(path.characters()) < 0) {
int saved_errno = errno;
GMessageBox::show(
String::format("unlink(%s) failed: %s", path.characters(), strerror(saved_errno)),