mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 11:47:35 +00:00
LibCore: Allow moving, but not copying, DirIterator
An explicit move constructor is required to null-out the moved-from directory descriptor. Otherwise, we would call closedir() twice when using ErrorOr<DirIterator>::release_value().
This commit is contained in:
parent
55e0b91d8d
commit
7f780e43a6
2 changed files with 13 additions and 0 deletions
|
@ -29,6 +29,16 @@ DirIterator::~DirIterator()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DirIterator::DirIterator(DirIterator&& other)
|
||||||
|
: m_dir(other.m_dir)
|
||||||
|
, m_error(other.m_error)
|
||||||
|
, m_next(move(other.m_next))
|
||||||
|
, m_path(move(other.m_path))
|
||||||
|
, m_flags(other.m_flags)
|
||||||
|
{
|
||||||
|
other.m_dir = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
bool DirIterator::advance_next()
|
bool DirIterator::advance_next()
|
||||||
{
|
{
|
||||||
if (!m_dir)
|
if (!m_dir)
|
||||||
|
|
|
@ -23,6 +23,9 @@ public:
|
||||||
explicit DirIterator(String path, Flags = Flags::NoFlags);
|
explicit DirIterator(String path, Flags = Flags::NoFlags);
|
||||||
~DirIterator();
|
~DirIterator();
|
||||||
|
|
||||||
|
DirIterator(DirIterator&&);
|
||||||
|
DirIterator(DirIterator const&) = delete;
|
||||||
|
|
||||||
bool has_error() const { return m_error != 0; }
|
bool has_error() const { return m_error != 0; }
|
||||||
int error() const { return m_error; }
|
int error() const { return m_error; }
|
||||||
const char* error_string() const { return strerror(m_error); }
|
const char* error_string() const { return strerror(m_error); }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue