now working with libuv v1.21.x

This commit is contained in:
Michele Caini 2018-06-27 13:40:48 +02:00
parent 10ae3f4e2e
commit 764f78ad61
4 changed files with 96 additions and 3 deletions

View File

@ -7,7 +7,7 @@ if(WIN32)
ExternalProject_Add(
libuv
GIT_REPOSITORY https://github.com/libuv/libuv.git
GIT_TAG v1.20.0
GIT_TAG v1.21.0
DOWNLOAD_DIR ${LIBUV_DEPS_DIR}
TMP_DIR ${LIBUV_DEPS_DIR}/tmp
STAMP_DIR ${LIBUV_DEPS_DIR}/stamp
@ -22,7 +22,7 @@ else()
ExternalProject_Add(
libuv
GIT_REPOSITORY https://github.com/libuv/libuv.git
GIT_TAG v1.20.0
GIT_TAG v1.21.0
DOWNLOAD_DIR ${LIBUV_DEPS_DIR}
TMP_DIR ${LIBUV_DEPS_DIR}/tmp
STAMP_DIR ${LIBUV_DEPS_DIR}/stamp

View File

@ -47,6 +47,7 @@ enum class UVFsType: std::underlying_type_t<uv_fs_type> {
READLINK = UV_FS_READLINK,
CHOWN = UV_FS_CHOWN,
FCHOWN = UV_FS_FCHOWN,
LCHOWN = UV_FS_LCHOWN,
REALPATH = UV_FS_REALPATH,
COPYFILE = UV_FS_COPYFILE
};
@ -139,6 +140,7 @@ enum class UVSymLinkFlags: int {
* * `FsRequest::Type::READLINK`
* * `FsRequest::Type::CHOWN`
* * `FsRequest::Type::FCHOWN`
* * `FsRequest::Type::LCHOWN`
* * `FsRequest::Type::REALPATH`
* * `FsRequest::Type::COPYFILE`
*
@ -1395,6 +1397,33 @@ public:
cleanupAndInvokeSync(&uv_fs_chown, parent(), req, path.data(), uid, gid);
return !(req->result < 0);
}
/**
* @brief Async [lchown](https://linux.die.net/man/2/lchown).
*
* Emit a `FsEvent<FsReq::Type::LCHOWN>` event when completed.<br/>
* Emit an ErrorEvent event in case of errors.
*
* @param path Path, as described in the official documentation.
* @param uid UID, as described in the official documentation.
* @param gid GID, as described in the official documentation.
*/
void lchown(std::string path, Uid uid, Gid gid) {
cleanupAndInvoke(&uv_fs_lchown, parent(), get(), path.data(), uid, gid, &fsGenericCallback<Type::LCHOWN>);
}
/**
* @brief Sync [lchown](https://linux.die.net/man/2/lchown).
* @param path Path, as described in the official documentation.
* @param uid UID, as described in the official documentation.
* @param gid GID, as described in the official documentation.
* @return True in case of success, false otherwise.
*/
bool lchownSync(std::string path, Uid uid, Gid gid) {
auto req = get();
cleanupAndInvokeSync(&uv_fs_lchown, parent(), req, path.data(), uid, gid);
return !(req->result < 0);
}
};

View File

@ -34,7 +34,8 @@ enum class UVStdIOFlags: std::underlying_type_t<uv_stdio_flags> {
INHERIT_FD = UV_INHERIT_FD,
INHERIT_STREAM = UV_INHERIT_STREAM,
READABLE_PIPE = UV_READABLE_PIPE,
WRITABLE_PIPE = UV_WRITABLE_PIPE
WRITABLE_PIPE = UV_WRITABLE_PIPE,
OVERLAPPED_PIPE = UV_OVERLAPPED_PIPE
};
@ -226,6 +227,7 @@ public:
* * `ProcessHandle::StdIO::INHERIT_STREAM`
* * `ProcessHandle::StdIO::READABLE_PIPE`
* * `ProcessHandle::StdIO::WRITABLE_PIPE`
* * `ProcessHandle::StdIO::OVERLAPPED_PIPE`
*
* See the official
* [documentation](http://docs.libuv.org/en/v1.x/process.html#c.uv_stdio_flags)
@ -256,6 +258,7 @@ public:
* * `ProcessHandle::StdIO::INHERIT_STREAM`
* * `ProcessHandle::StdIO::READABLE_PIPE`
* * `ProcessHandle::StdIO::WRITABLE_PIPE`
* * `ProcessHandle::StdIO::OVERLAPPED_PIPE`
*
* Default file descriptors are:
* * `uvw::StdIN` for `stdin`

View File

@ -726,3 +726,64 @@ TEST(FsReq, ChownSync) {
loop->run();
}
TEST(FsReq, Lchown) {
const std::string filename = std::string{TARGET_FS_REQ_DIR} + std::string{"/test.file"};
auto loop = uvw::Loop::getDefault();
auto fileReq = loop->resource<uvw::FileReq>();
auto fsReq = loop->resource<uvw::FsReq>();
bool checkFsLChownEvent = false;
fsReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fileReq->on<uvw::ErrorEvent>([](const auto &, auto &) { FAIL(); });
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::LCHOWN>>([&checkFsLChownEvent](const auto &, auto &) {
ASSERT_FALSE(checkFsLChownEvent);
checkFsLChownEvent = true;
});
fsReq->on<uvw::FsEvent<uvw::FsReq::Type::STAT>>([&filename](const auto &event, auto &request) {
auto uid = static_cast<uvw::Uid>(event.stat.st_uid);
auto gid = static_cast<uvw::Uid>(event.stat.st_gid);
request.lchown(filename, uid, gid);
});
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename](const auto &, auto &) {
fsReq->stat(filename);
});
fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &request) {
request.close();
});
auto flags = uvw::Flags<uvw::FileReq::FileOpen>::from<uvw::FileReq::FileOpen::CREAT, uvw::FileReq::FileOpen::RDWR, uvw::FileReq::FileOpen::TRUNC>();
fileReq->open(filename, flags, 0644);
loop->run();
ASSERT_TRUE(checkFsLChownEvent);
}
TEST(FsReq, LchownSync) {
const std::string filename = std::string{TARGET_FS_REQ_DIR} + std::string{"/test.file"};
auto loop = uvw::Loop::getDefault();
auto fileReq = loop->resource<uvw::FileReq>();
auto fsReq = loop->resource<uvw::FsReq>();
ASSERT_TRUE(fileReq->openSync(filename, O_CREAT | O_RDWR | O_TRUNC, 0644));
ASSERT_TRUE(fileReq->closeSync());
auto statR = fsReq->statSync(filename);
ASSERT_TRUE(statR.first);
auto uid = static_cast<uvw::Uid>(statR.second.st_uid);
auto gid = static_cast<uvw::Uid>(statR.second.st_gid);
ASSERT_TRUE(fsReq->lchownSync(filename, uid, gid));
loop->run();
}