mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 17:47:36 +00:00
LibCore+Everywhere: Return an Error from DirIterator::error()
This also removes DirIterator::error_string(), since the same strerror() string will be included when you print the Error itself. Except in `ls` which is still using fprintf() for now.
This commit is contained in:
parent
a98ae8f357
commit
774f328783
17 changed files with 44 additions and 46 deletions
|
@ -583,7 +583,7 @@ ErrorOr<void> DeprecatedFile::remove(StringView path, RecursionMode mode)
|
|||
if (S_ISDIR(path_stat.st_mode) && mode == RecursionMode::Allowed) {
|
||||
auto di = DirIterator(path, DirIterator::SkipParentAndBaseDir);
|
||||
if (di.has_error())
|
||||
return Error::from_errno(di.error());
|
||||
return di.error();
|
||||
|
||||
while (di.has_next()) {
|
||||
TRY(remove(di.next_full_path(), RecursionMode::Allowed));
|
||||
|
|
|
@ -17,7 +17,7 @@ DirIterator::DirIterator(DeprecatedString path, Flags flags)
|
|||
{
|
||||
m_dir = opendir(m_path.characters());
|
||||
if (!m_dir) {
|
||||
m_error = errno;
|
||||
m_error = Error::from_errno(errno);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ DirIterator::~DirIterator()
|
|||
|
||||
DirIterator::DirIterator(DirIterator&& other)
|
||||
: m_dir(other.m_dir)
|
||||
, m_error(other.m_error)
|
||||
, m_error(move(other.m_error))
|
||||
, m_next(move(other.m_next))
|
||||
, m_path(move(other.m_path))
|
||||
, m_flags(other.m_flags)
|
||||
|
@ -48,7 +48,7 @@ bool DirIterator::advance_next()
|
|||
errno = 0;
|
||||
auto* de = readdir(m_dir);
|
||||
if (!de) {
|
||||
m_error = errno;
|
||||
m_error = Error::from_errno(errno);
|
||||
m_next.clear();
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -28,9 +28,8 @@ public:
|
|||
DirIterator(DirIterator&&);
|
||||
DirIterator(DirIterator const&) = delete;
|
||||
|
||||
bool has_error() const { return m_error != 0; }
|
||||
int error() const { return m_error; }
|
||||
char const* error_string() const { return strerror(m_error); }
|
||||
bool has_error() const { return m_error.has_value(); }
|
||||
Error error() const { return Error::copy(m_error.value()); }
|
||||
bool has_next();
|
||||
Optional<DirectoryEntry> next();
|
||||
DeprecatedString next_path();
|
||||
|
@ -39,7 +38,7 @@ public:
|
|||
|
||||
private:
|
||||
DIR* m_dir = nullptr;
|
||||
int m_error = 0;
|
||||
Optional<Error> m_error;
|
||||
Optional<DirectoryEntry> m_next;
|
||||
DeprecatedString m_path;
|
||||
int m_flags;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue