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