1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 06:48:12 +00:00

LibCore: Use ErrorOr<T> for Core::File::remove()

This function returns a subclass of Error, which is now possible.
This commit is contained in:
Andreas Kling 2021-11-07 01:31:00 +01:00
parent e253cf694e
commit c7e62d448c
5 changed files with 17 additions and 14 deletions

View file

@ -546,17 +546,16 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_delete_action()
}
bool is_directory = S_ISDIR(st.st_mode);
auto result = Core::File::remove(file, Core::File::RecursionMode::Allowed, false);
if (result.is_error()) {
if (auto result = Core::File::remove(file, Core::File::RecursionMode::Allowed, false); !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),
String::formatted("Removing directory {} from the project failed: {}", error.file, static_cast<Error const&>(error)),
"Removal failed",
GUI::MessageBox::Type::Error);
} else {
GUI::MessageBox::show(window(),
String::formatted("Removing file {} from the project failed: {}", error.file, error.error_code),
String::formatted("Removing file {} from the project failed: {}", error.file, static_cast<Error const&>(error)),
"Removal failed",
GUI::MessageBox::Type::Error);
}