mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
LibCore: Let File::remove return a normal ErrorOr
Having the file path in there is nice, but it makes us incompatible with comfortable error propagation in everything that isn't File::remove.
This commit is contained in:
parent
7fa78b2456
commit
355e761a02
Notes:
sideshowbarker
2024-07-17 05:06:13 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/355e761a02 Pull-request: https://github.com/SerenityOS/serenity/pull/16636
4 changed files with 10 additions and 18 deletions
|
@ -368,8 +368,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
if (deletion_result.is_error()) {
|
||||
auto retry_message_result = GUI::MessageBox::show(window,
|
||||
DeprecatedString::formatted("Failed to delete \"{}\": {}. Retry?",
|
||||
deletion_result.error().file,
|
||||
static_cast<Error const&>(deletion_result.error())),
|
||||
selected_node_path,
|
||||
deletion_result.error()),
|
||||
"Deletion failed"sv,
|
||||
GUI::MessageBox::Type::Error,
|
||||
GUI::MessageBox::InputType::YesNo);
|
||||
|
|
|
@ -685,12 +685,12 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_delete_action()
|
|||
auto& error = result.error();
|
||||
if (is_directory) {
|
||||
GUI::MessageBox::show(window(),
|
||||
DeprecatedString::formatted("Removing directory {} from the project failed: {}", error.file, static_cast<Error const&>(error)),
|
||||
DeprecatedString::formatted("Removing directory {} from the project failed: {}", file, error),
|
||||
"Removal failed"sv,
|
||||
GUI::MessageBox::Type::Error);
|
||||
} else {
|
||||
GUI::MessageBox::show(window(),
|
||||
DeprecatedString::formatted("Removing file {} from the project failed: {}", error.file, static_cast<Error const&>(error)),
|
||||
DeprecatedString::formatted("Removing file {} from the project failed: {}", file, error),
|
||||
"Removal failed"sv,
|
||||
GUI::MessageBox::Type::Error);
|
||||
}
|
||||
|
|
|
@ -549,19 +549,19 @@ ErrorOr<void> File::link_file(DeprecatedString const& dst_path, DeprecatedString
|
|||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void, File::RemoveError> File::remove(DeprecatedString const& path, RecursionMode mode, bool force)
|
||||
ErrorOr<void> File::remove(DeprecatedString const& path, RecursionMode mode, bool force)
|
||||
{
|
||||
struct stat path_stat;
|
||||
if (lstat(path.characters(), &path_stat) < 0) {
|
||||
if (!force)
|
||||
return RemoveError { path, errno };
|
||||
return Error::from_errno(errno);
|
||||
return {};
|
||||
}
|
||||
|
||||
if (S_ISDIR(path_stat.st_mode) && mode == RecursionMode::Allowed) {
|
||||
auto di = DirIterator(path, DirIterator::SkipParentAndBaseDir);
|
||||
if (di.has_error())
|
||||
return RemoveError { path, di.error() };
|
||||
return Error::from_errno(di.error());
|
||||
|
||||
while (di.has_next()) {
|
||||
auto result = remove(di.next_full_path(), RecursionMode::Allowed, true);
|
||||
|
@ -570,10 +570,10 @@ ErrorOr<void, File::RemoveError> File::remove(DeprecatedString const& path, Recu
|
|||
}
|
||||
|
||||
if (rmdir(path.characters()) < 0 && !force)
|
||||
return RemoveError { path, errno };
|
||||
return Error::from_errno(errno);
|
||||
} else {
|
||||
if (unlink(path.characters()) < 0 && !force)
|
||||
return RemoveError { path, errno };
|
||||
return Error::from_errno(errno);
|
||||
}
|
||||
|
||||
return {};
|
||||
|
|
|
@ -93,15 +93,7 @@ public:
|
|||
static ErrorOr<DeprecatedString> read_link(DeprecatedString const& link_path);
|
||||
static ErrorOr<void> link_file(DeprecatedString const& dst_path, DeprecatedString const& src_path);
|
||||
|
||||
struct RemoveError : public Error {
|
||||
RemoveError(DeprecatedString f, int error_code)
|
||||
: Error(error_code)
|
||||
, file(move(f))
|
||||
{
|
||||
}
|
||||
DeprecatedString file;
|
||||
};
|
||||
static ErrorOr<void, RemoveError> remove(DeprecatedString const& path, RecursionMode, bool force);
|
||||
static ErrorOr<void> remove(DeprecatedString const& path, RecursionMode, bool force);
|
||||
|
||||
virtual bool open(OpenMode) override;
|
||||
|
||||
|
|
Loading…
Reference in a new issue