#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 |
120 other.loop_ = nullptr;
121 other.dir_ = nullptr;
122}
uv_dir_t * dir_
Definition fs.h:66
uv_loop_t * loop_
Definition fs.h:65
◆ ~Directory()
| uvco::Directory::~Directory |
( |
| ) |
|
void close()
Close the directory.
Definition fs.cc:223
◆ Directory() [3/3]
| uvco::Directory::Directory |
( |
uv_loop_t * | loop, |
|
|
uv_dir_t * | dir ) |
|
inlineexplicitprivate |
◆ close()
| void uvco::Directory::close |
( |
| ) |
|
Close the directory.
223 {
224 if (
dir_ !=
nullptr) {
226 }
228}
void onDirectoryDtorDone(uv_fs_t *req)
Definition fs.cc:137
◆ mkdir()
| Promise< void > uvco::Directory::mkdir |
( |
const Loop & | loop, |
|
|
std::string_view | path, |
|
|
int | mode = 0755 ) |
|
static |
Create a directory.
144 {
145 FileOpAwaiter_ awaiter;
146
147 const std::string path_str(path);
148 uv_fs_mkdir(loop.uvloop(), &awaiter.req(), path_str.c_str(), mode,
149 FileOpAwaiter_::uvCallback());
150
151 co_await awaiter;
152
153 co_return;
154}
◆ open()
Open a directory for reading.
168 {
169 FileOpAwaiter_ awaiter;
170
171 const std::string path_str(path);
172 uv_fs_opendir(loop.uvloop(), &awaiter.req(), path_str.c_str(),
173 FileOpAwaiter_::uvCallback());
174
175 co_await awaiter;
176
177 co_return Directory{loop.uvloop(), (uv_dir_t *)awaiter.req().ptr};
178}
Directory(const Directory &)=default
◆ operator=() [1/2]
◆ operator=() [2/2]
124 {
125 if (this == &other) {
126 return *this;
127 }
130 other.loop_ = nullptr;
131 other.dir_ = nullptr;
132 return *this;
133}
◆ read() [1/2]
| Promise< unsigned int > uvco::Directory::read |
( |
std::span< DirEnt > | buffer | ) |
|
Read up to buffer.size() directory entries into that buffer.
187 {
188
189
190 std::vector<uv_dirent_t> dirents(buffer.size());
191 dir_->dirents = dirents.data();
192 dir_->nentries = dirents.size();
193
194 FileOpAwaiter_ awaiter;
195
196 uv_fs_readdir(
loop_, &awaiter.req(),
dir_, FileOpAwaiter_::uvCallback());
197
198 co_await awaiter;
199
200 unsigned int nentries = awaiter.req().result;
201 for (unsigned i = 0; i < nentries; ++i) {
202 buffer[i].name = dirents[i].name;
203 buffer[i].type = dirents[i].type;
204 }
205 co_return nentries;
206}
◆ read() [2/2]
Read up to count directory entries.
180 {
181 std::vector<DirEnt> result{count};
182 const unsigned int size =
co_await read(result);
183 result.resize(size);
184 co_return result;
185}
Promise< std::vector< DirEnt > > read(unsigned count=64)
Read up to count directory entries.
Definition fs.cc:180
◆ readAll()
Read all directory entries of the given directory.
209 {
210 FileOpAwaiter_ awaiter;
211 uv_dirent_t dirent;
212 const std::string pathCopy{path};
213
214 uv_fs_scandir(loop.uvloop(), &awaiter.req(), pathCopy.c_str(), 0,
215 FileOpAwaiter_::uvCallback());
216
217 co_await awaiter;
218 while (UV_EOF != uv_fs_scandir_next(&awaiter.req(), &dirent)) {
219 co_yield DirEnt{.name = dirent.name, .type = dirent.type};
220 }
221}
◆ rmdir()
| Promise< void > uvco::Directory::rmdir |
( |
const Loop & | loop, |
|
|
std::string_view | path ) |
|
static |
Remove a directory. It must be empty.
156 {
157 FileOpAwaiter_ awaiter;
158
159 const std::string path_str(path);
160 uv_fs_rmdir(loop.uvloop(), &awaiter.req(), path_str.c_str(),
161 FileOpAwaiter_::uvCallback());
162
163 co_await awaiter;
164
165 co_return;
166}
◆ 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: