mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 17:38: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:
parent
e253cf694e
commit
c7e62d448c
5 changed files with 17 additions and 14 deletions
|
@ -512,19 +512,19 @@ ErrorOr<void> File::link_file(String const& dst_path, String const& src_path)
|
|||
return {};
|
||||
}
|
||||
|
||||
Result<void, File::RemoveError> File::remove(String const& path, RecursionMode mode, bool force)
|
||||
ErrorOr<void, File::RemoveError> File::remove(String const& path, RecursionMode mode, bool force)
|
||||
{
|
||||
struct stat path_stat;
|
||||
if (lstat(path.characters(), &path_stat) < 0) {
|
||||
if (!force)
|
||||
return RemoveError { path, OSError(errno) };
|
||||
return RemoveError { path, 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, OSError(di.error()) };
|
||||
return RemoveError { path, di.error() };
|
||||
|
||||
while (di.has_next()) {
|
||||
auto result = remove(di.next_full_path(), RecursionMode::Allowed, true);
|
||||
|
@ -533,10 +533,10 @@ Result<void, File::RemoveError> File::remove(String const& path, RecursionMode m
|
|||
}
|
||||
|
||||
if (rmdir(path.characters()) < 0 && !force)
|
||||
return RemoveError { path, OSError(errno) };
|
||||
return RemoveError { path, errno };
|
||||
} else {
|
||||
if (unlink(path.characters()) < 0 && !force)
|
||||
return RemoveError { path, OSError(errno) };
|
||||
return RemoveError { path, errno };
|
||||
}
|
||||
|
||||
return {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue