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

LibCore: Use a StringView for the file path in File::remove

This allows us to use our nice syscall wrappers, avoids some accidental
string copying, and starts to unlink us from the old DeprecatedString.
This commit is contained in:
Tim Schumacher 2022-12-23 14:33:05 +01:00 committed by Tim Flynn
parent 9805f73704
commit 8455d58a44
4 changed files with 8 additions and 14 deletions

View file

@ -549,11 +549,9 @@ ErrorOr<void> File::link_file(DeprecatedString const& dst_path, DeprecatedString
return {};
}
ErrorOr<void> File::remove(DeprecatedString const& path, RecursionMode mode)
ErrorOr<void> File::remove(StringView path, RecursionMode mode)
{
struct stat path_stat;
if (lstat(path.characters(), &path_stat) < 0)
return Error::from_errno(errno);
auto path_stat = TRY(Core::System::lstat(path));
if (S_ISDIR(path_stat.st_mode) && mode == RecursionMode::Allowed) {
auto di = DirIterator(path, DirIterator::SkipParentAndBaseDir);
@ -561,16 +559,12 @@ ErrorOr<void> File::remove(DeprecatedString const& path, RecursionMode mode)
return Error::from_errno(di.error());
while (di.has_next()) {
auto result = remove(di.next_full_path(), RecursionMode::Allowed);
if (result.is_error())
return result.error();
TRY(remove(di.next_full_path(), RecursionMode::Allowed));
}
if (rmdir(path.characters()) < 0)
return Error::from_errno(errno);
TRY(Core::System::rmdir(path));
} else {
if (unlink(path.characters()) < 0)
return Error::from_errno(errno);
TRY(Core::System::unlink(path));
}
return {};