#include <fs.h>
|
static Promise< void > | mkdir (const Loop &loop, std::string_view path, int mode=0755) |
| Create a directory.
|
|
static Promise< void > | rmdir (const Loop &loop, std::string_view path) |
| Remove a directory. It must be empty.
|
|
static Promise< Directory > | open (const Loop &loop, std::string_view path) |
| Open a directory for reading.
|
|
static MultiPromise< DirEnt > | readAll (const Loop &loop, std::string_view path) |
| Read all directory entries of the given directory.
|
|
◆ Directory() [1/3]
uvco::Directory::Directory |
( |
const Directory & |
| ) |
|
|
default |
◆ Directory() [2/3]
uvco::Directory::Directory |
( |
Directory && |
other | ) |
|
|
noexcept |
98 other.loop_ = nullptr;
99 other.dir_ = nullptr;
100}
uv_dir_t * dir_
Definition fs.h:66
uv_loop_t * loop_
Definition fs.h:65
◆ ~Directory()
uvco::Directory::~Directory |
( |
| ) |
|
113 {
114 if (
dir_ !=
nullptr) {
115 auto req = std::make_unique<uv_fs_t>();
116 uv_fs_closedir(
loop_, req.release(),
dir_,
nullptr);
117 fmt::print(stderr, "Directory closed in dtor; this leaks memory. Please "
118 "use co_await close() instead\n");
119 }
120}
◆ Directory() [3/3]
uvco::Directory::Directory |
( |
uv_loop_t * |
loop, |
|
|
uv_dir_t * |
dir |
|
) |
| |
|
inlineexplicitprivate |
◆ close()
Promise< void > uvco::Directory::close |
( |
| ) |
|
Close the directory.
199 {
200 FileOpAwaiter_ awaiter;
201 uv_fs_closedir(
loop_, &awaiter.req(),
dir_, FileOpAwaiter_::uvCallback());
202 co_await awaiter;
204 co_return;
205}
◆ mkdir()
Promise< void > uvco::Directory::mkdir |
( |
const Loop & |
loop, |
|
|
std::string_view |
path, |
|
|
int |
mode = 0755 |
|
) |
| |
|
static |
Create a directory.
123 {
124 FileOpAwaiter_ awaiter;
125
126 uv_fs_mkdir(loop.uvloop(), &awaiter.req(), path.data(), mode,
127 FileOpAwaiter_::uvCallback());
128
129 co_await awaiter;
130
131 co_return;
132}
◆ open()
Open a directory for reading.
145 {
146 FileOpAwaiter_ awaiter;
147
148 uv_fs_opendir(loop.uvloop(), &awaiter.req(), path.data(),
149 FileOpAwaiter_::uvCallback());
150
151 co_await awaiter;
152
153 co_return Directory{loop.uvloop(), (uv_dir_t *)awaiter.req().ptr};
154}
Directory(const Directory &)=default
◆ operator=() [1/2]
◆ operator=() [2/2]
102 {
103 if (this == &other) {
104 return *this;
105 }
108 other.loop_ = nullptr;
109 other.dir_ = nullptr;
110 return *this;
111}
◆ read() [1/2]
Promise< unsigned int > uvco::Directory::read |
( |
std::span< DirEnt > |
buffer | ) |
|
Read up to buffer.size()
directory entries into that buffer.
163 {
164
165
166 std::vector<uv_dirent_t> dirents{buffer.size()};
167 dir_->dirents = dirents.data();
168 dir_->nentries = dirents.size();
169
170 FileOpAwaiter_ awaiter;
171
172 uv_fs_readdir(
loop_, &awaiter.req(),
dir_, FileOpAwaiter_::uvCallback());
173
174 co_await awaiter;
175
176 unsigned int nentries = awaiter.req().result;
177 for (unsigned i = 0; i < nentries; ++i) {
178 buffer[i].name = dirents[i].name;
179 buffer[i].type = dirents[i].type;
180 }
181 co_return nentries;
182}
◆ read() [2/2]
Read up to count
directory entries.
156 {
157 std::vector<DirEnt> result{count};
158 const unsigned int size =
co_await read(result);
159 result.resize(size);
160 co_return result;
161}
Promise< std::vector< DirEnt > > read(unsigned count=64)
Read up to count directory entries.
Definition fs.cc:156
◆ readAll()
Read all directory entries of the given directory.
185 {
186 FileOpAwaiter_ awaiter;
187 uv_dirent_t dirent;
188 const std::string pathCopy{path};
189
190 uv_fs_scandir(loop.uvloop(), &awaiter.req(), pathCopy.c_str(), 0,
191 FileOpAwaiter_::uvCallback());
192
193 co_await awaiter;
194 while (UV_EOF != uv_fs_scandir_next(&awaiter.req(), &dirent)) {
195 co_yield DirEnt{dirent.name, dirent.type};
196 }
197}
◆ rmdir()
Promise< void > uvco::Directory::rmdir |
( |
const Loop & |
loop, |
|
|
std::string_view |
path |
|
) |
| |
|
static |
Remove a directory. It must be empty.
134 {
135 FileOpAwaiter_ awaiter;
136
137 uv_fs_rmdir(loop.uvloop(), &awaiter.req(), path.data(),
138 FileOpAwaiter_::uvCallback());
139
140 co_await awaiter;
141
142 co_return;
143}
◆ dir_
uv_dir_t* uvco::Directory::dir_ |
|
private |
◆ loop_
uv_loop_t* uvco::Directory::loop_ |
|
private |
The documentation for this class was generated from the following files: