6#include "uringpp/awaitable.h"
7#include "uringpp/event_loop.h"
9#include "uringpp/detail/noncopyable.h"
19 std::shared_ptr<event_loop> loop_;
28 int fd()
const {
return fd_; }
36 dir(std::shared_ptr<event_loop> loop,
int fd) : loop_(loop), fd_(
fd) {}
44 : loop_(std::move(other.loop_)), fd_(std::exchange(other.fd_, -1)) {}
52 loop_->close_detach(fd_);
63 co_await loop_->close(fd_);
77 static task<dir> open(std::shared_ptr<event_loop> loop,
char const *path,
78 int flags, mode_t mode) {
79 int fd =
co_await loop->openat(AT_FDCWD, path, flags, mode);
80 check_nerrno(
fd,
"failed to open dir");
81 co_return dir(loop,
fd);
95 char const *path,
int flags, mode_t mode) {
96 int fd =
co_await loop->openat(
dir.
fd(), path, flags, mode);
97 check_nerrno(
fd,
"failed to open dir");
111 char const *path,
struct open_how *how) {
112 int fd =
co_await loop->openat2(
dir.
fd(), path, how);
113 check_nerrno(
fd,
"failed to open dir");
127 struct statx *statxbuf) {
128 return loop_->statx(fd_, path, flags, mask, statxbuf);
139 return loop_->mkdirat(fd_, path, mode);
150 return loop_->symlinkat(oldpath, fd_, newpath);
163 const char *newpath) {
164 return loop_->symlinkat(oldpath, newdir.
fd(), newpath);
176 return loop_->linkat(fd_, oldpath, fd_, newpath, flags);
189 const char *newpath,
int flags) {
190 return loop_->linkat(fd_, oldpath, newdir.
fd(), newpath, flags);
202 return loop_->renameat(fd_, oldpath, fd_, newpath, flags);
215 const char *newpath,
int flags) {
216 return loop_->renameat(fd_, oldpath, newdir.
fd(), newpath, flags);
227 return loop_->unlinkat(fd_, path, flags);
An opened directory.
Definition: dir.h:17
sqe_awaitable symlink(const char *oldpath, dir const &newdir, const char *newpath)
Symbolic link a file/directory in the directory to another directory.
Definition: dir.h:162
sqe_awaitable unlink(const char *path, int flags)
Unlink a file/directory in the directory.
Definition: dir.h:226
dir(dir &&other) noexcept
Move construct a new dir object.
Definition: dir.h:43
sqe_awaitable rename(const char *oldpath, const char *newpath, int flags)
Rename a file/directory in the directory.
Definition: dir.h:201
task< void > close()
Close the directory.
Definition: dir.h:61
static task< dir > open(std::shared_ptr< event_loop > loop, char const *path, int flags, mode_t mode)
Open a directory in the current working directory.
Definition: dir.h:77
sqe_awaitable link(const char *oldpath, dir const &newdir, const char *newpath, int flags)
Link a file/directory in the directory to another directory.
Definition: dir.h:188
static task< dir > openat2(std::shared_ptr< event_loop > loop, dir const &dir, char const *path, struct open_how *how)
Open a directory in the given directory.
Definition: dir.h:110
dir(std::shared_ptr< event_loop > loop, int fd)
Construct a new dir object from a file descriptor.
Definition: dir.h:36
static task< dir > openat(std::shared_ptr< event_loop > loop, dir const &dir, char const *path, int flags, mode_t mode)
Open a directory in the given directory.
Definition: dir.h:94
int fd() const
Get the file descriptor of the directory.
Definition: dir.h:28
sqe_awaitable rename(const char *oldpath, dir const &newdir, const char *newpath, int flags)
Rename a file/directory in the directory to another directory.
Definition: dir.h:214
sqe_awaitable mkdir(const char *path, mode_t mode)
Make a directory.
Definition: dir.h:138
sqe_awaitable statx(const char *path, int flags, unsigned mask, struct statx *statxbuf)
Stat a file/directory in the directory.
Definition: dir.h:126
~dir()
Destroy the dir object. If the directory is open, it will be closed.
Definition: dir.h:50
sqe_awaitable link(const char *oldpath, const char *newpath, int flags)
Link a file/directory in the directory.
Definition: dir.h:175
sqe_awaitable symlink(const char *oldpath, const char *newpath)
Symbolic link a file/directory in the directory.
Definition: dir.h:149
Definition: noncopyable.h:5
Definition: awaitable.h:10