|
|
|
|
@ -70,8 +70,48 @@ template<details::UVFsType e>
|
|
|
|
|
struct TypedEvent<details::UVFsType, e>
|
|
|
|
|
: Event<TypedEvent<details::UVFsType, e>>
|
|
|
|
|
{
|
|
|
|
|
using Type = details::UVFsType;
|
|
|
|
|
static constexpr details::UVFsType value = e;
|
|
|
|
|
TypedEvent(const char *p) noexcept
|
|
|
|
|
: rPath{p}
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
const char * path() const noexcept { return rPath; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const char *rPath;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
struct TypedEvent<details::UVFsType, details::UVFsType::WRITE>
|
|
|
|
|
: Event<TypedEvent<details::UVFsType, details::UVFsType::WRITE>>
|
|
|
|
|
{
|
|
|
|
|
TypedEvent(const char *p, ssize_t s) noexcept
|
|
|
|
|
: rPath{p}, sz{s}
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
const char * path() const noexcept { return rPath; }
|
|
|
|
|
ssize_t amount() const noexcept { return sz; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const char *rPath;
|
|
|
|
|
const ssize_t sz;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
struct TypedEvent<details::UVFsType, details::UVFsType::SENDFILE>
|
|
|
|
|
: Event<TypedEvent<details::UVFsType, details::UVFsType::SENDFILE>>
|
|
|
|
|
{
|
|
|
|
|
TypedEvent(const char *p, ssize_t s) noexcept
|
|
|
|
|
: rPath{p}, sz{s}
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
const char * path() const noexcept { return rPath; }
|
|
|
|
|
ssize_t amount() const noexcept { return sz; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const char *rPath;
|
|
|
|
|
const ssize_t sz;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -79,14 +119,15 @@ template<>
|
|
|
|
|
struct TypedEvent<details::UVFsType, details::UVFsType::STAT>
|
|
|
|
|
: Event<TypedEvent<details::UVFsType, details::UVFsType::STAT>>
|
|
|
|
|
{
|
|
|
|
|
using Type = details::UVFsType;
|
|
|
|
|
static constexpr details::UVFsType value = details::UVFsType::STAT;
|
|
|
|
|
|
|
|
|
|
TypedEvent(const Stat &s): fsStat{s} { }
|
|
|
|
|
TypedEvent(const char *p, const Stat &s) noexcept
|
|
|
|
|
: rPath{p}, fsStat{s}
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
const char * path() const noexcept { return rPath; }
|
|
|
|
|
const Stat & stat() const noexcept { return fsStat; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const char *rPath;
|
|
|
|
|
Stat fsStat;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@ -95,14 +136,15 @@ template<>
|
|
|
|
|
struct TypedEvent<details::UVFsType, details::UVFsType::FSTAT>
|
|
|
|
|
: Event<TypedEvent<details::UVFsType, details::UVFsType::FSTAT>>
|
|
|
|
|
{
|
|
|
|
|
using Type = details::UVFsType;
|
|
|
|
|
static constexpr details::UVFsType value = details::UVFsType::FSTAT;
|
|
|
|
|
|
|
|
|
|
TypedEvent(const Stat &s): fsStat{s} { }
|
|
|
|
|
TypedEvent(const char *p, const Stat &s) noexcept
|
|
|
|
|
: rPath{p}, fsStat{s}
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
const char * path() const noexcept { return rPath; }
|
|
|
|
|
const Stat & stat() const noexcept { return fsStat; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const char *rPath;
|
|
|
|
|
Stat fsStat;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@ -111,71 +153,129 @@ template<>
|
|
|
|
|
struct TypedEvent<details::UVFsType, details::UVFsType::LSTAT>
|
|
|
|
|
: Event<TypedEvent<details::UVFsType, details::UVFsType::LSTAT>>
|
|
|
|
|
{
|
|
|
|
|
using Type = details::UVFsType;
|
|
|
|
|
static constexpr details::UVFsType value = details::UVFsType::LSTAT;
|
|
|
|
|
|
|
|
|
|
TypedEvent(const Stat &s): fsStat{s} { }
|
|
|
|
|
TypedEvent(const char *p, const Stat &s) noexcept
|
|
|
|
|
: rPath{p}, fsStat{s}
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
const char * path() const noexcept { return rPath; }
|
|
|
|
|
const Stat & stat() const noexcept { return fsStat; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const char *rPath;
|
|
|
|
|
Stat fsStat;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
struct TypedEvent<details::UVFsType, details::UVFsType::SCANDIR>
|
|
|
|
|
: Event<TypedEvent<details::UVFsType, details::UVFsType::SCANDIR>>
|
|
|
|
|
{
|
|
|
|
|
TypedEvent(const char *p, ssize_t s) noexcept
|
|
|
|
|
: rPath{p}, sz{s}
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
const char * path() const noexcept { return rPath; }
|
|
|
|
|
ssize_t amount() const noexcept { return sz; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const char *rPath;
|
|
|
|
|
const ssize_t sz;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
struct TypedEvent<details::UVFsType, details::UVFsType::READLINK>
|
|
|
|
|
: Event<TypedEvent<details::UVFsType, details::UVFsType::READLINK>>
|
|
|
|
|
{
|
|
|
|
|
explicit TypedEvent(const char *p, const char *d, ssize_t l) noexcept
|
|
|
|
|
: rPath{p}, dt{d}, len{l}
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
const char * path() const noexcept { return rPath; }
|
|
|
|
|
const char * data() const noexcept { return dt; }
|
|
|
|
|
ssize_t length() const noexcept { return len; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const char *rPath;
|
|
|
|
|
const char *dt;
|
|
|
|
|
const ssize_t len;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<details::UVFsType e>
|
|
|
|
|
using FsEvent = TypedEvent<details::UVFsType, e>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Fs final: public Request<Fs, uv_fs_t> {
|
|
|
|
|
template<details::UVFsType e>
|
|
|
|
|
static void fsGenericCallback(uv_fs_t *req) {
|
|
|
|
|
Fs &fs = *(static_cast<Fs*>(req->data));
|
|
|
|
|
static constexpr int BAD_FD = -1;
|
|
|
|
|
|
|
|
|
|
auto ptr = fs.shared_from_this();
|
|
|
|
|
(void)ptr;
|
|
|
|
|
|
|
|
|
|
fs.reset();
|
|
|
|
|
static void fsCloseCallback(uv_fs_t *req) {
|
|
|
|
|
auto ptr = reserve(reinterpret_cast<uv_req_t*>(req));
|
|
|
|
|
|
|
|
|
|
if(req->result) {
|
|
|
|
|
int err = req->result;
|
|
|
|
|
fs.publish(ErrorEvent{err});
|
|
|
|
|
ptr->publish(ErrorEvent{req->result});
|
|
|
|
|
} else {
|
|
|
|
|
fs.publish(FsEvent<e>{});
|
|
|
|
|
ptr->file = BAD_FD;
|
|
|
|
|
ptr->publish(FsEvent<Type::CLOSE>{req->path});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void fsOpenCallback(uv_fs_t *req) {
|
|
|
|
|
auto ptr = reserve(reinterpret_cast<uv_req_t*>(req));
|
|
|
|
|
|
|
|
|
|
if(req->result < 0) {
|
|
|
|
|
ptr->publish(ErrorEvent{req->result});
|
|
|
|
|
} else {
|
|
|
|
|
ptr->file = req->result;
|
|
|
|
|
ptr->publish(FsEvent<Type::OPEN>{req->path});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<details::UVFsType e>
|
|
|
|
|
static void fsGenericCallback(uv_fs_t *req) {
|
|
|
|
|
auto ptr = reserve(reinterpret_cast<uv_req_t*>(req));
|
|
|
|
|
if(req->result) { ptr->publish(ErrorEvent{req->result}); }
|
|
|
|
|
else { ptr->publish(FsEvent<e>{req->path}); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void fsReadCallback(uv_fs_t *req) {
|
|
|
|
|
// TODO - uv_fs_read callback
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void fsWriteCallback(uv_fs_t *req) {
|
|
|
|
|
// TODO - uv_fs_write callback
|
|
|
|
|
template<details::UVFsType e>
|
|
|
|
|
static void fsResultCallback(uv_fs_t *req) {
|
|
|
|
|
auto ptr = reserve(reinterpret_cast<uv_req_t*>(req));
|
|
|
|
|
if(req->result < 0) { ptr->publish(ErrorEvent{req->result}); }
|
|
|
|
|
else { ptr->publish(FsEvent<e>{req->path, req->result}); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<details::UVFsType e>
|
|
|
|
|
static void fsStatCallback(uv_fs_t *req) {
|
|
|
|
|
Fs &fs = *(static_cast<Fs*>(req->data));
|
|
|
|
|
|
|
|
|
|
auto ptr = fs.shared_from_this();
|
|
|
|
|
(void)ptr;
|
|
|
|
|
|
|
|
|
|
fs.reset();
|
|
|
|
|
|
|
|
|
|
if(req->result) {
|
|
|
|
|
int err = req->result;
|
|
|
|
|
fs.publish(ErrorEvent{err});
|
|
|
|
|
} else {
|
|
|
|
|
fs.publish(FsEvent<e>{req->statbuf});
|
|
|
|
|
}
|
|
|
|
|
auto ptr = reserve(reinterpret_cast<uv_req_t*>(req));
|
|
|
|
|
if(req->result) { ptr->publish(ErrorEvent{req->result}); }
|
|
|
|
|
else { ptr->publish(FsEvent<e>{req->path, req->statbuf}); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void fsReadlinkCallback(uv_fs_t *req) {
|
|
|
|
|
// TODO - uv_fs_readlink callback
|
|
|
|
|
auto ptr = reserve(reinterpret_cast<uv_req_t*>(req));
|
|
|
|
|
if(req->result < 0) { ptr->publish(ErrorEvent{req->result}); }
|
|
|
|
|
else { ptr->publish(FsEvent<Type::READLINK>{req->path, static_cast<char *>(req->ptr), req->result}); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using Request::Request;
|
|
|
|
|
|
|
|
|
|
template<typename... Args>
|
|
|
|
|
void cleanupAndInvoke(Args&&... args) {
|
|
|
|
|
uv_fs_req_cleanup(get<uv_fs_t>());
|
|
|
|
|
invoke(std::forward<Args>(args)...);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename F, typename... Args>
|
|
|
|
|
void cleanupAndInvokeSync(F &&f, Args&&... args) {
|
|
|
|
|
uv_fs_req_cleanup(get<uv_fs_t>());
|
|
|
|
|
std::forward<F>(f)(std::forward<Args>(args)...);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
using Time = std::chrono::seconds;
|
|
|
|
|
using Type = details::UVFsType;
|
|
|
|
|
@ -191,86 +291,99 @@ public:
|
|
|
|
|
uv_fs_req_cleanup(get<uv_fs_t>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void close(FileHandle file) {
|
|
|
|
|
invoke(&uv_fs_close, parent(), get<uv_fs_t>(), file, &fsGenericCallback<Type::CLOSE>);
|
|
|
|
|
void close() {
|
|
|
|
|
cleanupAndInvoke(&uv_fs_close, parent(), get<uv_fs_t>(), file, &fsCloseCallback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto closeSync(FileHandle file) {
|
|
|
|
|
auto err = uv_fs_close(parent(), get<uv_fs_t>(), file, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::CLOSE>{});
|
|
|
|
|
auto closeSync() {
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_close, parent(), req, file, nullptr);
|
|
|
|
|
if(!req->result) { file = BAD_FD; }
|
|
|
|
|
return std::make_pair(ErrorEvent{req->result}, FsEvent<Type::CLOSE>{req->path});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void open(std::string path, int flags, int mode) {
|
|
|
|
|
invoke(&uv_fs_open, parent(), get<uv_fs_t>(), path.data(), flags, mode, &fsGenericCallback<Type::OPEN>);
|
|
|
|
|
cleanupAndInvoke(&uv_fs_open, parent(), get<uv_fs_t>(), path.data(), flags, mode, &fsOpenCallback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto openSync(std::string path, int flags, int mode) {
|
|
|
|
|
auto err = uv_fs_open(parent(), get<uv_fs_t>(), path.data(), flags, mode, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::OPEN>{});
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_open, parent(), req, path.data(), flags, mode, nullptr);
|
|
|
|
|
auto fd = req->result;
|
|
|
|
|
if(fd >= 0) { file = fd; }
|
|
|
|
|
return std::make_pair(ErrorEvent{fd < 0 ? fd : 0}, FsEvent<Type::OPEN>{req->path});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO uv_fs_read (sync (cb null)/async)
|
|
|
|
|
void read(int64_t offset, unsigned int len) {
|
|
|
|
|
// TODO uv_fs_read (async)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto readSync(int64_t offset, unsigned int len) {
|
|
|
|
|
// TODO uv_fs_read (sync (cb null))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void unlink(std::string path) {
|
|
|
|
|
invoke(&uv_fs_unlink, parent(), get<uv_fs_t>(), path.data(), &fsGenericCallback<Type::UNLINK>);
|
|
|
|
|
cleanupAndInvoke(&uv_fs_unlink, parent(), get<uv_fs_t>(), path.data(), &fsGenericCallback<Type::UNLINK>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto unlinkSync(std::string path) {
|
|
|
|
|
auto err = uv_fs_unlink(parent(), get<uv_fs_t>(), path.data(), nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::UNLINK>{});
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_unlink, parent(), req, path.data(), nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{req->result}, FsEvent<Type::UNLINK>{req->path});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void write(FileHandle file, char *data, ssize_t len, int64_t offset) {
|
|
|
|
|
uv_buf_t bufs[] = { uv_buf_init(data, len) };
|
|
|
|
|
invoke(&uv_fs_write, parent(), get<uv_fs_t>(), file, bufs, 1, offset, &fsWriteCallback);
|
|
|
|
|
void write(std::unique_ptr<char[]> data, ssize_t len, int64_t offset) {
|
|
|
|
|
uv_buf_t bufs[] = { uv_buf_init(data.get(), len) };
|
|
|
|
|
cleanupAndInvoke(&uv_fs_write, parent(), get<uv_fs_t>(), file, bufs, 1, offset, &fsResultCallback<Type::WRITE>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void write(FileHandle file, std::unique_ptr<char[]> data, ssize_t len, int64_t offset) {
|
|
|
|
|
write(file, data.get(), len, offset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto writeSync(FileHandle file, char *data, ssize_t len, int64_t offset) {
|
|
|
|
|
// TODO uv_fs_write (sync (cb null))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto writeSync(FileHandle file, std::unique_ptr<char[]> data, ssize_t len, int64_t offset) {
|
|
|
|
|
// TODO uv_fs_write (sync (cb null))
|
|
|
|
|
auto writeSync(std::unique_ptr<char[]> data, ssize_t len, int64_t offset) {
|
|
|
|
|
uv_buf_t bufs[] = { uv_buf_init(data.get(), len) };
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_write, parent(), get<uv_fs_t>(), file, bufs, 1, offset, nullptr);
|
|
|
|
|
auto bw = req->result;
|
|
|
|
|
return std::make_pair(ErrorEvent{bw < 0 ? bw : 0}, FsEvent<Type::WRITE>{req->path, bw});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void mkdir(std::string path, int mode) {
|
|
|
|
|
invoke(&uv_fs_mkdir, parent(), get<uv_fs_t>(), path.data(), mode, &fsGenericCallback<Type::MKDIR>);
|
|
|
|
|
cleanupAndInvoke(&uv_fs_mkdir, parent(), get<uv_fs_t>(), path.data(), mode, &fsGenericCallback<Type::MKDIR>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto mkdirSync(std::string path, int mode) {
|
|
|
|
|
auto err = uv_fs_mkdir(parent(), get<uv_fs_t>(), path.data(), mode, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::MKDIR>{});
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_mkdir, parent(), req, path.data(), mode, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{req->result}, FsEvent<Type::MKDIR>{req->path});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void mkdtemp(std::string tpl) {
|
|
|
|
|
invoke(&uv_fs_mkdtemp, parent(), get<uv_fs_t>(), tpl.data(), &fsGenericCallback<Type::MKDTEMP>);
|
|
|
|
|
cleanupAndInvoke(&uv_fs_mkdtemp, parent(), get<uv_fs_t>(), tpl.data(), &fsGenericCallback<Type::MKDTEMP>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto mkdtempSync(std::string tpl) {
|
|
|
|
|
auto err = uv_fs_mkdtemp(parent(), get<uv_fs_t>(), tpl.data(), nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::MKDTEMP>{});
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_mkdtemp, parent(), req, tpl.data(), nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{req->result}, FsEvent<Type::MKDTEMP>{req->path});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void rmdir(std::string path) {
|
|
|
|
|
invoke(&uv_fs_rmdir, parent(), get<uv_fs_t>(), path.data(), &fsGenericCallback<Type::RMDIR>);
|
|
|
|
|
cleanupAndInvoke(&uv_fs_rmdir, parent(), get<uv_fs_t>(), path.data(), &fsGenericCallback<Type::RMDIR>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto rmdirSync(std::string path) {
|
|
|
|
|
auto err = uv_fs_rmdir(parent(), get<uv_fs_t>(), path.data(), nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::RMDIR>{});
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_rmdir, parent(), req, path.data(), nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{req->result}, FsEvent<Type::RMDIR>{req->path});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void scandir(std::string path, int flags) {
|
|
|
|
|
invoke(&uv_fs_scandir, parent(), get<uv_fs_t>(), path.data(), flags, &fsGenericCallback<Type::SCANDIR>);
|
|
|
|
|
cleanupAndInvoke(&uv_fs_scandir, parent(), get<uv_fs_t>(), path.data(), flags, &fsResultCallback<Type::SCANDIR>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto scandirSync(std::string path, int flags) {
|
|
|
|
|
auto err = uv_fs_scandir(parent(), get<uv_fs_t>(), path.data(), flags, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::SCANDIR>{});
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_scandir, parent(), req, path.data(), flags, nullptr);
|
|
|
|
|
auto sz = req->result;
|
|
|
|
|
return std::make_pair(ErrorEvent{sz < 0 ? sz : 0}, FsEvent<Type::SCANDIR>{req->path, sz});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::pair<bool, Entry> scandirNext() {
|
|
|
|
|
@ -288,172 +401,201 @@ public:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void stat(std::string path) {
|
|
|
|
|
invoke(&uv_fs_stat, parent(), get<uv_fs_t>(), path.data(), &fsStatCallback<Type::STAT>);
|
|
|
|
|
cleanupAndInvoke(&uv_fs_stat, parent(), get<uv_fs_t>(), path.data(), &fsStatCallback<Type::STAT>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto statSync(std::string path) {
|
|
|
|
|
auto err = uv_fs_stat(parent(), get<uv_fs_t>(), path.data(), nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::STAT>{get<uv_fs_t>()->statbuf});
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_stat, parent(), req, path.data(), nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{req->result}, FsEvent<Type::STAT>{req->path, req->statbuf});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void fstat(FileHandle file) {
|
|
|
|
|
invoke(&uv_fs_fstat, parent(), get<uv_fs_t>(), file, &fsStatCallback<Type::FSTAT>);
|
|
|
|
|
void fstat() {
|
|
|
|
|
cleanupAndInvoke(&uv_fs_fstat, parent(), get<uv_fs_t>(), file, &fsStatCallback<Type::FSTAT>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto fstatSync(FileHandle file) {
|
|
|
|
|
auto err = uv_fs_fstat(parent(), get<uv_fs_t>(), file, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::FSTAT>{get<uv_fs_t>()->statbuf});
|
|
|
|
|
auto fstatSync() {
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_fstat, parent(), req, file, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{req->result}, FsEvent<Type::FSTAT>{req->path, req->statbuf});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void lstat(std::string path) {
|
|
|
|
|
invoke(&uv_fs_lstat, parent(), get<uv_fs_t>(), path.data(), &fsStatCallback<Type::LSTAT>);
|
|
|
|
|
cleanupAndInvoke(&uv_fs_lstat, parent(), get<uv_fs_t>(), path.data(), &fsStatCallback<Type::LSTAT>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto lstatSync(std::string path) {
|
|
|
|
|
auto err = uv_fs_lstat(parent(), get<uv_fs_t>(), path.data(), nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::LSTAT>{get<uv_fs_t>()->statbuf});
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_lstat, parent(), req, path.data(), nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{req->result}, FsEvent<Type::LSTAT>{req->path, req->statbuf});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void rename(std::string old, std::string path) {
|
|
|
|
|
invoke(&uv_fs_rename, parent(), get<uv_fs_t>(), old.data(), path.data(), &fsGenericCallback<Type::RENAME>);
|
|
|
|
|
cleanupAndInvoke(&uv_fs_rename, parent(), get<uv_fs_t>(), old.data(), path.data(), &fsGenericCallback<Type::RENAME>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto renameSync(std::string old, std::string path) {
|
|
|
|
|
auto err = uv_fs_rename(parent(), get<uv_fs_t>(), old.data(), path.data(), nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::RENAME>{});
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_rename, parent(), req, old.data(), path.data(), nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{req->result}, FsEvent<Type::RENAME>{req->path});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void fsync(FileHandle file) {
|
|
|
|
|
invoke(&uv_fs_fsync, parent(), get<uv_fs_t>(), file, &fsGenericCallback<Type::FSYNC>);
|
|
|
|
|
void fsync() {
|
|
|
|
|
cleanupAndInvoke(&uv_fs_fsync, parent(), get<uv_fs_t>(), file, &fsGenericCallback<Type::FSYNC>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto fsyncSync(FileHandle file) {
|
|
|
|
|
auto err = uv_fs_fsync(parent(), get<uv_fs_t>(), file, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::FSYNC>{});
|
|
|
|
|
auto fsyncSync() {
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_fsync, parent(), req, file, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{req->result}, FsEvent<Type::FSYNC>{req->path});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void fdatasync(FileHandle file) {
|
|
|
|
|
invoke(&uv_fs_fdatasync, parent(), get<uv_fs_t>(), file, &fsGenericCallback<Type::FDATASYNC>);
|
|
|
|
|
void fdatasync() {
|
|
|
|
|
cleanupAndInvoke(&uv_fs_fdatasync, parent(), get<uv_fs_t>(), file, &fsGenericCallback<Type::FDATASYNC>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto fdatasyncSync(FileHandle file) {
|
|
|
|
|
auto err = uv_fs_fdatasync(parent(), get<uv_fs_t>(), file, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::FDATASYNC>{});
|
|
|
|
|
auto fdatasyncSync() {
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_fdatasync, parent(), req, file, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{req->result}, FsEvent<Type::FDATASYNC>{req->path});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ftruncate(FileHandle file, int64_t offset) {
|
|
|
|
|
invoke(&uv_fs_ftruncate, parent(), get<uv_fs_t>(), file, offset, &fsGenericCallback<Type::FTRUNCATE>);
|
|
|
|
|
void ftruncate(int64_t offset) {
|
|
|
|
|
cleanupAndInvoke(&uv_fs_ftruncate, parent(), get<uv_fs_t>(), file, offset, &fsGenericCallback<Type::FTRUNCATE>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto ftruncateSync(FileHandle file, int64_t offset) {
|
|
|
|
|
auto err = uv_fs_ftruncate(parent(), get<uv_fs_t>(), file, offset, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::FTRUNCATE>{});
|
|
|
|
|
auto ftruncateSync(int64_t offset) {
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_ftruncate, parent(), req, file, offset, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{req->result}, FsEvent<Type::FTRUNCATE>{req->path});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void sendfile(FileHandle out, FileHandle in, int64_t offset, size_t length) {
|
|
|
|
|
invoke(&uv_fs_sendfile, parent(), get<uv_fs_t>(), out, in, offset, length, &fsGenericCallback<Type::SENDFILE>);
|
|
|
|
|
void sendfile(FileHandle out, int64_t offset, size_t length) {
|
|
|
|
|
cleanupAndInvoke(&uv_fs_sendfile, parent(), get<uv_fs_t>(), out, file, offset, length, &fsResultCallback<Type::SENDFILE>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto sendfileSync(FileHandle out, FileHandle in, int64_t offset, size_t length) {
|
|
|
|
|
auto err = uv_fs_sendfile(parent(), get<uv_fs_t>(), out, in, offset, length, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::SENDFILE>{});
|
|
|
|
|
auto sendfileSync(FileHandle out, int64_t offset, size_t length) {
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_sendfile, parent(), req, out, file, offset, length, nullptr);
|
|
|
|
|
auto bw = req->result;
|
|
|
|
|
return std::make_pair(ErrorEvent{bw < 0 ? bw : 0}, FsEvent<Type::SENDFILE>{req->path, bw});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void access(std::string path, int mode) {
|
|
|
|
|
invoke(&uv_fs_access, parent(), get<uv_fs_t>(), path.data(), mode, &fsGenericCallback<Type::ACCESS>);
|
|
|
|
|
cleanupAndInvoke(&uv_fs_access, parent(), get<uv_fs_t>(), path.data(), mode, &fsGenericCallback<Type::ACCESS>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto accessSync(std::string path, int mode) {
|
|
|
|
|
auto err = uv_fs_access(parent(), get<uv_fs_t>(), path.data(), mode, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::ACCESS>{});
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_access, parent(), req, path.data(), mode, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{req->result}, FsEvent<Type::ACCESS>{req->path});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void chmod(std::string path, int mode) {
|
|
|
|
|
invoke(&uv_fs_chmod, parent(), get<uv_fs_t>(), path.data(), mode, &fsGenericCallback<Type::CHMOD>);
|
|
|
|
|
cleanupAndInvoke(&uv_fs_chmod, parent(), get<uv_fs_t>(), path.data(), mode, &fsGenericCallback<Type::CHMOD>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto chmodSync(std::string path, int mode) {
|
|
|
|
|
auto err = uv_fs_chmod(parent(), get<uv_fs_t>(), path.data(), mode, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::CHMOD>{});
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_chmod, parent(), req, path.data(), mode, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{req->result}, FsEvent<Type::CHMOD>{req->path});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void fchmod(FileHandle file, int mode) {
|
|
|
|
|
invoke(&uv_fs_fchmod, parent(), get<uv_fs_t>(), file, mode, &fsGenericCallback<Type::FCHMOD>);
|
|
|
|
|
void fchmod(int mode) {
|
|
|
|
|
cleanupAndInvoke(&uv_fs_fchmod, parent(), get<uv_fs_t>(), file, mode, &fsGenericCallback<Type::FCHMOD>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto fchmodSync(FileHandle file, int mode) {
|
|
|
|
|
auto err = uv_fs_fchmod(parent(), get<uv_fs_t>(), file, mode, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::FCHMOD>{});
|
|
|
|
|
auto fchmodSync(int mode) {
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_fchmod, parent(), req, file, mode, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{req->result}, FsEvent<Type::FCHMOD>{req->path});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void utime(std::string path, Time atime, Time mtime) {
|
|
|
|
|
invoke(&uv_fs_utime, parent(), get<uv_fs_t>(), path.data(), atime.count(), mtime.count(), &fsGenericCallback<Type::UTIME>);
|
|
|
|
|
cleanupAndInvoke(&uv_fs_utime, parent(), get<uv_fs_t>(), path.data(), atime.count(), mtime.count(), &fsGenericCallback<Type::UTIME>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto utimeSync(std::string path, Time atime, Time mtime) {
|
|
|
|
|
auto err = uv_fs_utime(parent(), get<uv_fs_t>(), path.data(), atime.count(), mtime.count(), nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::UTIME>{});
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_utime, parent(), req, path.data(), atime.count(), mtime.count(), nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{req->result}, FsEvent<Type::UTIME>{req->path});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void futime(FileHandle file, Time atime, Time mtime) {
|
|
|
|
|
invoke(&uv_fs_futime, parent(), get<uv_fs_t>(), file, atime.count(), mtime.count(), &fsGenericCallback<Type::FUTIME>);
|
|
|
|
|
void futime(Time atime, Time mtime) {
|
|
|
|
|
cleanupAndInvoke(&uv_fs_futime, parent(), get<uv_fs_t>(), file, atime.count(), mtime.count(), &fsGenericCallback<Type::FUTIME>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto futimeSync(FileHandle file, Time atime, Time mtime) {
|
|
|
|
|
auto err = uv_fs_futime(parent(), get<uv_fs_t>(), file, atime.count(), mtime.count(), nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::FUTIME>{});
|
|
|
|
|
auto futimeSync(Time atime, Time mtime) {
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_futime, parent(), req, file, atime.count(), mtime.count(), nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{req->result}, FsEvent<Type::FUTIME>{req->path});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void link(std::string old, std::string path) {
|
|
|
|
|
invoke(&uv_fs_link, parent(), get<uv_fs_t>(), old.data(), path.data(), &fsGenericCallback<Type::LINK>);
|
|
|
|
|
cleanupAndInvoke(&uv_fs_link, parent(), get<uv_fs_t>(), old.data(), path.data(), &fsGenericCallback<Type::LINK>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto linkSync(std::string old, std::string path) {
|
|
|
|
|
auto err = uv_fs_link(parent(), get<uv_fs_t>(), old.data(), path.data(), nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::LINK>{});
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_link, parent(), req, old.data(), path.data(), nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{req->result}, FsEvent<Type::LINK>{req->path});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void symlink(std::string old, std::string path, int flags) {
|
|
|
|
|
invoke(&uv_fs_symlink, parent(), get<uv_fs_t>(), old.data(), path.data(), flags, &fsGenericCallback<Type::SYMLINK>);
|
|
|
|
|
cleanupAndInvoke(&uv_fs_symlink, parent(), get<uv_fs_t>(), old.data(), path.data(), flags, &fsGenericCallback<Type::SYMLINK>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto symlinkSync(std::string old, std::string path, int flags) {
|
|
|
|
|
auto err = uv_fs_symlink(parent(), get<uv_fs_t>(), old.data(), path.data(), flags, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::SYMLINK>{});
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_symlink, parent(), req, old.data(), path.data(), flags, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{req->result}, FsEvent<Type::SYMLINK>{req->path});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void readlink(std::string path) {
|
|
|
|
|
invoke(&uv_fs_readlink, parent(), get<uv_fs_t>(), path.data(), &fsReadlinkCallback);
|
|
|
|
|
cleanupAndInvoke(&uv_fs_readlink, parent(), get<uv_fs_t>(), path.data(), &fsReadlinkCallback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO uv_fs_readlink (sync (cb null))
|
|
|
|
|
auto readlinkSync(std::string path) {
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_readlink, parent(), req, path.data(), nullptr);
|
|
|
|
|
auto bw = req->result;
|
|
|
|
|
return std::make_pair(ErrorEvent{bw < 0 ? bw : 0}, FsEvent<Type::READLINK>{req->path, static_cast<char *>(req->ptr), bw});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void realpath(std::string path) {
|
|
|
|
|
invoke(&uv_fs_realpath, parent(), get<uv_fs_t>(), path.data(), &fsGenericCallback<Type::REALPATH>);
|
|
|
|
|
cleanupAndInvoke(&uv_fs_realpath, parent(), get<uv_fs_t>(), path.data(), &fsGenericCallback<Type::REALPATH>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto realpathSync(std::string path) {
|
|
|
|
|
auto err = uv_fs_realpath(parent(), get<uv_fs_t>(), path.data(), nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::REALPATH>{});
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_realpath, parent(), req, path.data(), nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{req->result}, FsEvent<Type::REALPATH>{req->path});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void chown(std::string path, Uid uid, Gid gid) {
|
|
|
|
|
invoke(&uv_fs_chown, parent(), get<uv_fs_t>(), path.data(), uid, gid, &fsGenericCallback<Type::CHOWN>);
|
|
|
|
|
cleanupAndInvoke(&uv_fs_chown, parent(), get<uv_fs_t>(), path.data(), uid, gid, &fsGenericCallback<Type::CHOWN>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto chownSync(std::string path, Uid uid, Gid gid) {
|
|
|
|
|
auto err = uv_fs_chown(parent(), get<uv_fs_t>(), path.data(), uid, gid, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::CHOWN>{});
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_chown, parent(), req, path.data(), uid, gid, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{req->result}, FsEvent<Type::CHOWN>{req->path});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void fchown(FileHandle file, Uid uid, Gid gid) {
|
|
|
|
|
invoke(&uv_fs_fchown, parent(), get<uv_fs_t>(), file, uid, gid, &fsGenericCallback<Type::FCHOWN>);
|
|
|
|
|
void fchown(Uid uid, Gid gid) {
|
|
|
|
|
cleanupAndInvoke(&uv_fs_fchown, parent(), get<uv_fs_t>(), file, uid, gid, &fsGenericCallback<Type::FCHOWN>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto fchownSync(FileHandle file, Uid uid, Gid gid) {
|
|
|
|
|
auto err = uv_fs_fchown(parent(), get<uv_fs_t>(), file, uid, gid, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{err}, FsEvent<Type::FCHOWN>{});
|
|
|
|
|
auto fchownSync(Uid uid, Gid gid) {
|
|
|
|
|
auto req = get<uv_fs_t>();
|
|
|
|
|
cleanupAndInvokeSync(&uv_fs_fchown, parent(), req, file, uid, gid, nullptr);
|
|
|
|
|
return std::make_pair(ErrorEvent{req->result}, FsEvent<Type::FCHOWN>{req->path});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
operator FileHandle() const noexcept { return file; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
uv_file file{BAD_FD};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|