This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathDirectoryEntry.h
67 lines (56 loc) · 2.04 KB
/
DirectoryEntry.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
This file is part of duckOS.
duckOS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
duckOS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with duckOS. If not, see <https://www.gnu.org/licenses/>.
Copyright (c) Byteduck 2016-2021. All rights reserved.
*/
#pragma once
#include "Path.h"
#include <dirent.h>
#include <string_view>
#include <vector>
#include "DataSize.h"
namespace Duck {
class DirectoryEntry {
public:
enum Type {
UNKNOWN = DT_UNKNOWN,
REGULAR = DT_REG,
DIRECTORY = DT_DIR,
CHARDEVICE = DT_CHR,
BLOCKDEVICE = DT_BLK,
FIFO = DT_FIFO,
SOCKET = DT_SOCK,
SYMLINK = DT_LNK
};
DirectoryEntry(const Path& parent_path, const dirent* entry);
[[nodiscard]] std::string_view name() const { return m_name; }
[[nodiscard]] Type type() const { return m_type; }
[[nodiscard]] ino_t inode() const { return m_inode; }
[[nodiscard]] DataSize size() const { return m_size; }
[[nodiscard]] mode_t mode() const { return m_mode; }
[[nodiscard]] const Path& path() const { return m_path; }
[[nodiscard]] bool is_regular() const { return m_type == REGULAR; }
[[nodiscard]] bool is_directory() const { return m_type == DIRECTORY; }
[[nodiscard]] bool is_chardev() const { return m_type == CHARDEVICE; }
[[nodiscard]] bool is_blockdev() const { return m_type == BLOCKDEVICE; }
[[nodiscard]] bool is_fifo() const { return m_type == FIFO; }
[[nodiscard]] bool is_socket() const { return m_type == SOCKET; }
[[nodiscard]] bool is_symlink() const { return m_type == SYMLINK; }
private:
ino_t m_inode;
Type m_type;
std::string m_name;
DataSize m_size;
mode_t m_mode;
Path m_path;
};
}