mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:17:35 +00:00
LibCore: Remove the force
parameter from File::remove
About half of the usages were not using `force` anyways, and the other half presumably just got confused about what "force" really means in this context (which is "ignore nonexistent files"). The only 'legitimate' user, which is `rm`, instead now handles this completely internally instead.
This commit is contained in:
parent
355e761a02
commit
9805f73704
10 changed files with 22 additions and 20 deletions
|
@ -549,14 +549,11 @@ ErrorOr<void> File::link_file(DeprecatedString const& dst_path, DeprecatedString
|
|||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> File::remove(DeprecatedString const& path, RecursionMode mode, bool force)
|
||||
ErrorOr<void> File::remove(DeprecatedString const& path, RecursionMode mode)
|
||||
{
|
||||
struct stat path_stat;
|
||||
if (lstat(path.characters(), &path_stat) < 0) {
|
||||
if (!force)
|
||||
return Error::from_errno(errno);
|
||||
return {};
|
||||
}
|
||||
if (lstat(path.characters(), &path_stat) < 0)
|
||||
return Error::from_errno(errno);
|
||||
|
||||
if (S_ISDIR(path_stat.st_mode) && mode == RecursionMode::Allowed) {
|
||||
auto di = DirIterator(path, DirIterator::SkipParentAndBaseDir);
|
||||
|
@ -564,15 +561,15 @@ ErrorOr<void> File::remove(DeprecatedString const& path, RecursionMode mode, boo
|
|||
return Error::from_errno(di.error());
|
||||
|
||||
while (di.has_next()) {
|
||||
auto result = remove(di.next_full_path(), RecursionMode::Allowed, true);
|
||||
auto result = remove(di.next_full_path(), RecursionMode::Allowed);
|
||||
if (result.is_error())
|
||||
return result.error();
|
||||
}
|
||||
|
||||
if (rmdir(path.characters()) < 0 && !force)
|
||||
if (rmdir(path.characters()) < 0)
|
||||
return Error::from_errno(errno);
|
||||
} else {
|
||||
if (unlink(path.characters()) < 0 && !force)
|
||||
if (unlink(path.characters()) < 0)
|
||||
return Error::from_errno(errno);
|
||||
}
|
||||
|
||||
|
|
|
@ -93,7 +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);
|
||||
|
||||
static ErrorOr<void> remove(DeprecatedString const& path, RecursionMode, bool force);
|
||||
static ErrorOr<void> remove(DeprecatedString const& path, RecursionMode);
|
||||
|
||||
virtual bool open(OpenMode) override;
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ TempFile::~TempFile()
|
|||
if (m_type == Type::Directory)
|
||||
recursion_allowed = File::RecursionMode::Allowed;
|
||||
|
||||
auto rc = File::remove(m_path.characters(), recursion_allowed, false);
|
||||
auto rc = File::remove(m_path.characters(), recursion_allowed);
|
||||
if (rc.is_error()) {
|
||||
warnln("File::remove failed: {}", rc.error().string_literal());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue