1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 01:17:46 +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:
Sam Atkins 2023-03-01 15:55:15 +00:00 committed by Andreas Kling
parent a98ae8f357
commit 774f328783
17 changed files with 44 additions and 46 deletions

View file

@ -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));

View file

@ -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;
}

View file

@ -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;

View file

@ -99,8 +99,9 @@ void FileSystemModel::Node::traverse_if_needed()
auto full_path = this->full_path();
Core::DirIterator di(full_path, m_model.should_show_dotfiles() ? Core::DirIterator::SkipParentAndBaseDir : Core::DirIterator::SkipDots);
if (di.has_error()) {
m_error = di.error();
warnln("DirIterator: {}", di.error_string());
auto error = di.error();
m_error = error.code();
warnln("DirIterator: {}", error);
return;
}

View file

@ -130,7 +130,7 @@ void FontDatabase::load_all_fonts_from_path(DeprecatedString const& root)
auto current_directory = path_queue.dequeue();
Core::DirIterator dir_iterator(current_directory, Core::DirIterator::SkipParentAndBaseDir);
if (dir_iterator.has_error()) {
dbgln("FontDatabase::load_all_fonts_from_path: {}", dir_iterator.error_string());
dbgln("FontDatabase::load_all_fonts_from_path: {}", dir_iterator.error());
continue;
}
while (dir_iterator.has_next()) {