2020-01-18 08:38:21 +00:00
|
|
|
/*
|
2024-10-04 11:19:50 +00:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2023-03-02 15:39:07 +00:00
|
|
|
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
|
2020-01-18 08:38:21 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 08:38:21 +00:00
|
|
|
*/
|
|
|
|
|
2019-05-27 07:26:54 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-03-02 15:39:07 +00:00
|
|
|
#include <LibCore/DirectoryEntry.h>
|
2019-05-27 07:26:54 +00:00
|
|
|
|
2020-02-02 11:34:39 +00:00
|
|
|
namespace Core {
|
|
|
|
|
|
|
|
class DirIterator {
|
2019-05-27 07:26:54 +00:00
|
|
|
public:
|
2019-06-07 15:13:23 +00:00
|
|
|
enum Flags {
|
2019-05-27 07:26:54 +00:00
|
|
|
NoFlags = 0x0,
|
|
|
|
SkipDots = 0x1,
|
2020-02-15 00:06:08 +00:00
|
|
|
SkipParentAndBaseDir = 0x2,
|
2024-01-06 09:38:43 +00:00
|
|
|
NoStat = 0x4,
|
2019-05-27 07:26:54 +00:00
|
|
|
};
|
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
explicit DirIterator(ByteString path, Flags = Flags::NoFlags);
|
2020-02-02 11:34:39 +00:00
|
|
|
~DirIterator();
|
2019-05-27 07:26:54 +00:00
|
|
|
|
2021-11-23 16:37:14 +00:00
|
|
|
DirIterator(DirIterator&&);
|
|
|
|
DirIterator(DirIterator const&) = delete;
|
|
|
|
|
2023-03-01 15:55:15 +00:00
|
|
|
bool has_error() const { return m_error.has_value(); }
|
|
|
|
Error error() const { return Error::copy(m_error.value()); }
|
2019-05-27 07:26:54 +00:00
|
|
|
bool has_next();
|
2023-03-02 15:39:07 +00:00
|
|
|
Optional<DirectoryEntry> next();
|
2023-12-16 14:19:34 +00:00
|
|
|
ByteString next_path();
|
|
|
|
ByteString next_full_path();
|
2021-05-14 19:05:18 +00:00
|
|
|
int fd() const;
|
2019-05-27 07:26:54 +00:00
|
|
|
|
|
|
|
private:
|
2024-10-24 17:22:11 +00:00
|
|
|
DIR* m_dir = nullptr;
|
2023-03-01 15:55:15 +00:00
|
|
|
Optional<Error> m_error;
|
2023-03-02 15:39:07 +00:00
|
|
|
Optional<DirectoryEntry> m_next;
|
2023-12-16 14:19:34 +00:00
|
|
|
ByteString m_path;
|
2019-05-27 07:26:54 +00:00
|
|
|
int m_flags;
|
|
|
|
|
|
|
|
bool advance_next();
|
|
|
|
};
|
2020-02-02 11:34:39 +00:00
|
|
|
|
|
|
|
}
|