From 764f78ad61ec17ac5bf6ca1d02f6b9a04b00b77d Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Wed, 27 Jun 2018 13:40:48 +0200 Subject: [PATCH] now working with libuv v1.21.x --- cmake/in/libuv.in | 4 +-- src/uvw/fs.hpp | 29 +++++++++++++++++++++ src/uvw/process.hpp | 5 +++- test/uvw/fs_req.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 3 deletions(-) diff --git a/cmake/in/libuv.in b/cmake/in/libuv.in index 6edc3771..1f85a2a1 100644 --- a/cmake/in/libuv.in +++ b/cmake/in/libuv.in @@ -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 diff --git a/src/uvw/fs.hpp b/src/uvw/fs.hpp index 576c4917..30373c3a 100644 --- a/src/uvw/fs.hpp +++ b/src/uvw/fs.hpp @@ -47,6 +47,7 @@ enum class UVFsType: std::underlying_type_t { 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` event when completed.
+ * 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); + } + + /** + * @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); + } }; diff --git a/src/uvw/process.hpp b/src/uvw/process.hpp index 02afee99..cbb892ec 100644 --- a/src/uvw/process.hpp +++ b/src/uvw/process.hpp @@ -34,7 +34,8 @@ enum class UVStdIOFlags: std::underlying_type_t { 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` diff --git a/test/uvw/fs_req.cpp b/test/uvw/fs_req.cpp index f57b40ec..ab358043 100644 --- a/test/uvw/fs_req.cpp +++ b/test/uvw/fs_req.cpp @@ -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(); + auto fsReq = loop->resource(); + + bool checkFsLChownEvent = false; + + fsReq->on([](const auto &, auto &) { FAIL(); }); + fileReq->on([](const auto &, auto &) { FAIL(); }); + + fsReq->on>([&checkFsLChownEvent](const auto &, auto &) { + ASSERT_FALSE(checkFsLChownEvent); + checkFsLChownEvent = true; + }); + + fsReq->on>([&filename](const auto &event, auto &request) { + auto uid = static_cast(event.stat.st_uid); + auto gid = static_cast(event.stat.st_gid); + request.lchown(filename, uid, gid); + }); + + fileReq->on>([&fsReq, &filename](const auto &, auto &) { + fsReq->stat(filename); + }); + + fileReq->on>([](const auto &, auto &request) { + request.close(); + }); + + auto flags = uvw::Flags::from(); + 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(); + auto fsReq = loop->resource(); + + 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(statR.second.st_uid); + auto gid = static_cast(statR.second.st_gid); + ASSERT_TRUE(fsReq->lchownSync(filename, uid, gid)); + + loop->run(); +}