From a05733db597731abb9f110ab8cf2a34d20a587b4 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Fri, 18 Aug 2017 19:09:41 +0200 Subject: [PATCH] now working with libuv 1.14.0 --- CMakeLists.txt | 2 +- cmake/in/libuv.in | 4 +- src/uvw/fs.hpp | 136 +++++++++++++++++++++++++++++++++++++------- src/uvw/poll.hpp | 6 +- test/uvw/fs_req.cpp | 14 ++++- 5 files changed, 136 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ef2d6de8..fb7a6e3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ endif() # Project configuration # -project(uvw VERSION 1.1.1) +project(uvw VERSION 1.2.0) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug) diff --git a/cmake/in/libuv.in b/cmake/in/libuv.in index e30dcd97..8cd3646b 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.13.1 + GIT_TAG v1.14.0 DOWNLOAD_DIR ${LIBUV_DEPS_DIR} TMP_DIR ${LIBUV_DEPS_DIR}/tmp STAMP_DIR ${LIBUV_DEPS_DIR}/stamp @@ -22,7 +22,7 @@ else(WIN32) ExternalProject_Add( libuv GIT_REPOSITORY https://github.com/libuv/libuv.git - GIT_TAG v1.13.1 + GIT_TAG v1.14.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 c50bc660..06701f3b 100644 --- a/src/uvw/fs.hpp +++ b/src/uvw/fs.hpp @@ -47,7 +47,8 @@ enum class UVFsType: std::underlying_type_t { READLINK = UV_FS_READLINK, CHOWN = UV_FS_CHOWN, FCHOWN = UV_FS_FCHOWN, - REALPATH = UV_FS_REALPATH + REALPATH = UV_FS_REALPATH, + COPYFILE = UV_FS_COPYFILE }; @@ -63,6 +64,17 @@ enum class UVDirentTypeT: std::underlying_type_t { }; +enum class UVCopyFileFlags: int { + EXCL = UV_FS_COPYFILE_EXCL +}; + + +enum class UVSymLinkFlags: int { + DIR = UV_FS_SYMLINK_DIR, + JUNCTION = UV_FS_SYMLINK_JUNCTION +}; + + } @@ -101,6 +113,7 @@ enum class UVDirentTypeT: std::underlying_type_t { * * `FsRequest::Type::CHOWN` * * `FsRequest::Type::FCHOWN` * * `FsRequest::Type::REALPATH` + * * `FsRequest::Type::COPYFILE` * * It will be emitted by FsReq and/or FileReq according with their * functionalities. @@ -696,6 +709,20 @@ public: return !(req->result < 0); } + /** + * @brief Gets the OS dependent handle. + * + * For a file descriptor in the C runtime, get the OS-dependent handle. On + * UNIX, returns the file descriptor as-is. On Windows, this calls a system + * function.
+ * Note that the return value is still owned by the C runtime, any attempts + * to close it or to use it after closing the file descriptor may lead to + * malfunction. + */ + OSFileDescriptor handle() const noexcept { + return uv_get_osfhandle(file); + } + /** * @brief Cast operator to FileHandle. * @@ -733,6 +760,9 @@ class FsReq final: public FsRequest { } public: + using CopyFile = details::UVCopyFileFlags; + using SymLink = details::UVSymLinkFlags; + using FsRequest::FsRequest; ~FsReq() noexcept { @@ -742,7 +772,7 @@ public: /** * @brief Async [unlink](http://linux.die.net/man/2/unlink). * - * Emit a `FsEvent` event when completed.
+ * Emit a `FsEvent` event when completed.
* Emit an ErrorEvent event in case of errors. * * @param path Path, as described in the official documentation. @@ -765,7 +795,7 @@ public: /** * @brief Async [mkdir](http://linux.die.net/man/2/mkdir). * - * Emit a `FsEvent` event when completed.
+ * Emit a `FsEvent` event when completed.
* Emit an ErrorEvent event in case of errors. * * @param path Path, as described in the official documentation. @@ -790,7 +820,7 @@ public: /** * @brief Async [mktemp](http://linux.die.net/man/3/mkdtemp). * - * Emit a `FsEvent` event when completed.
+ * Emit a `FsEvent` event when completed.
* Emit an ErrorEvent event in case of errors. * * @param tpl Template, as described in the official documentation. @@ -817,7 +847,7 @@ public: /** * @brief Async [rmdir](http://linux.die.net/man/2/rmdir). * - * Emit a `FsEvent` event when completed.
+ * Emit a `FsEvent` event when completed.
* Emit an ErrorEvent event in case of errors. * * @param path Path, as described in the official documentation. @@ -840,7 +870,7 @@ public: /** * @brief Async [scandir](http://linux.die.net/man/3/scandir). * - * Emit a `FsEvent` event when completed.
+ * Emit a `FsEvent` event when completed.
* Emit an ErrorEvent event in case of errors. * * @param path Path, as described in the official documentation. @@ -913,7 +943,7 @@ public: /** * @brief Async [stat](http://linux.die.net/man/2/stat). * - * Emit a `FsEvent` event when completed.
+ * Emit a `FsEvent` event when completed.
* Emit an ErrorEvent event in case of errors. * * @param path Path, as described in the official documentation. @@ -940,7 +970,7 @@ public: /** * @brief Async [lstat](http://linux.die.net/man/2/lstat). * - * Emit a `FsEvent` event when completed.
+ * Emit a `FsEvent` event when completed.
* Emit an ErrorEvent event in case of errors. * * @param path Path, as described in the official documentation. @@ -967,7 +997,7 @@ public: /** * @brief Async [rename](http://linux.die.net/man/2/rename). * - * Emit a `FsEvent` event when completed.
+ * Emit a `FsEvent` event when completed.
* Emit an ErrorEvent event in case of errors. * * @param old Old path, as described in the official documentation. @@ -989,10 +1019,61 @@ public: return !(req->result < 0); } + /** + * @brief Copies a file asynchronously from a path to a new one. + * + * Emit a `FsEvent` event when + * completed.
+ * Emit an ErrorEvent event in case of errors. + * + * Available flags are: + * + * * `FsReq::CopyFile::EXCL`: it fails if the destination path + * already exists (the default behavior is to overwrite the destination if + * it exists). + * + * If the destination path is created, but an error occurs while copying the + * data, then the destination path is removed. There is a brief window of + * time between closing and removing the file where another process could + * access the file. + * + * @param old Old path, as described in the official documentation. + * @param path New path, as described in the official documentation. + * @param flags Optional additional flags. + */ + void copyfile(std::string old, std::string path, Flags flags = Flags{}) { + cleanupAndInvoke(&uv_fs_copyfile, parent(), get(), old.data(), path.data(), flags, &fsGenericCallback); + } + + /** + * @brief Copies a file synchronously from a path to a new one. + * + * Available flags are: + * + * * `FsReq::CopyFile::EXCL`: it fails if the destination path + * already exists (the default behavior is to overwrite the destination if + * it exists). + * + * If the destination path is created, but an error occurs while copying the + * data, then the destination path is removed. There is a brief window of + * time between closing and removing the file where another process could + * access the file. + * + * @param old Old path, as described in the official documentation. + * @param path New path, as described in the official documentation. + * @param flags Optional additional flags. + * @return True in case of success, false otherwise. + */ + bool copyfileSync(std::string old, std::string path, Flags flags = Flags{}) { + auto req = get(); + cleanupAndInvokeSync(&uv_fs_copyfile, parent(), get(), old.data(), path.data(), flags); + return !(req->result < 0); + } + /** * @brief Async [access](http://linux.die.net/man/2/access). * - * Emit a `FsEvent` event when completed.
+ * Emit a `FsEvent` event when completed.
* Emit an ErrorEvent event in case of errors. * * @param path Path, as described in the official documentation. @@ -1017,7 +1098,7 @@ public: /** * @brief Async [chmod](http://linux.die.net/man/2/chmod). * - * Emit a `FsEvent` event when completed.
+ * Emit a `FsEvent` event when completed.
* Emit an ErrorEvent event in case of errors. * * @param path Path, as described in the official documentation. @@ -1042,7 +1123,7 @@ public: /** * @brief Async [utime](http://linux.die.net/man/2/utime). * - * Emit a `FsEvent` event when completed.
+ * Emit a `FsEvent` event when completed.
* Emit an ErrorEvent event in case of errors. * * @param path Path, as described in the official documentation. @@ -1073,7 +1154,7 @@ public: /** * @brief Async [link](http://linux.die.net/man/2/link). * - * Emit a `FsEvent` event when completed.
+ * Emit a `FsEvent` event when completed.
* Emit an ErrorEvent event in case of errors. * * @param old Old path, as described in the official documentation. @@ -1098,25 +1179,40 @@ public: /** * @brief Async [symlink](http://linux.die.net/man/2/symlink). * - * Emit a `FsEvent` event when completed.
+ * Emit a `FsEvent` event when completed.
* Emit an ErrorEvent event in case of errors. * + * Available flags are: + * + * * `FsReq::SymLink::DIR`: it indicates that the old path points to a + * directory. + * * `FsReq::SymLink::JUNCTION`: it requests that the symlink is created + * using junction points. + * * @param old Old path, as described in the official documentation. * @param path New path, as described in the official documentation. - * @param flags Flags, as described in the official documentation. + * @param flags Optional additional flags. */ - void symlink(std::string old, std::string path, int flags) { + void symlink(std::string old, std::string path, Flags flags = Flags{}) { cleanupAndInvoke(&uv_fs_symlink, parent(), get(), old.data(), path.data(), flags, &fsGenericCallback); } /** * @brief Sync [symlink](http://linux.die.net/man/2/symlink). + * + * Available flags are: + * + * * `FsReq::SymLink::DIR`: it indicates that the old path points to a + * directory. + * * `FsReq::SymLink::JUNCTION`: it requests that the symlink is created + * using junction points. + * * @param old Old path, as described in the official documentation. * @param path New path, as described in the official documentation. * @param flags Flags, as described in the official documentation. * @return True in case of success, false otherwise. */ - bool symlinkSync(std::string old, std::string path, int flags) { + bool symlinkSync(std::string old, std::string path, Flags flags = Flags{}) { auto req = get(); cleanupAndInvokeSync(&uv_fs_symlink, parent(), req, old.data(), path.data(), flags); return !(req->result < 0); @@ -1125,7 +1221,7 @@ public: /** * @brief Async [readlink](http://linux.die.net/man/2/readlink). * - * Emit a `FsEvent` event when completed.
+ * Emit a `FsEvent` event when completed.
* Emit an ErrorEvent event in case of errors. * * @param path Path, as described in the official documentation. @@ -1156,7 +1252,7 @@ public: /** * @brief Async [realpath](http://linux.die.net/man/3/realpath). * - * Emit a `FsEvent` event when completed.
+ * Emit a `FsEvent` event when completed.
* Emit an ErrorEvent event in case of errors. * * @param path Path, as described in the official documentation. @@ -1183,7 +1279,7 @@ public: /** * @brief Async [chown](http://linux.die.net/man/2/chown). * - * Emit a `FsEvent` event when completed.
+ * Emit a `FsEvent` event when completed.
* Emit an ErrorEvent event in case of errors. * * @param path Path, as described in the official documentation. diff --git a/src/uvw/poll.hpp b/src/uvw/poll.hpp index 966153db..dae3c14a 100644 --- a/src/uvw/poll.hpp +++ b/src/uvw/poll.hpp @@ -18,7 +18,8 @@ namespace details { enum class UVPollEvent: std::underlying_type_t { READABLE = UV_READABLE, WRITABLE = UV_WRITABLE, - DISCONNECT = UV_DISCONNECT + DISCONNECT = UV_DISCONNECT, + PRIORITIZED = UV_PRIORITIZED }; @@ -43,6 +44,7 @@ struct PollEvent { * * `PollHandle::Event::READABLE` * * `PollHandle::Event::WRITABLE` * * `PollHandle::Event::DISCONNECT` + * * `PollHandle::Event::PRIORITIZED` */ Flags flags; }; @@ -100,6 +102,7 @@ public: * * `PollHandle::Event::READABLE` * * `PollHandle::Event::WRITABLE` * * `PollHandle::Event::DISCONNECT` + * * `PollHandle::Event::PRIORITIZED` * * As soon as an event is detected, a PollEvent is emitted by the * handle.
@@ -122,6 +125,7 @@ public: * * `PollHandle::Event::READABLE` * * `PollHandle::Event::WRITABLE` * * `PollHandle::Event::DISCONNECT` + * * `PollHandle::Event::PRIORITIZED` * * As soon as an event is detected, a PollEvent is emitted by the * handle.
diff --git a/test/uvw/fs_req.cpp b/test/uvw/fs_req.cpp index 78b66838..f9cb74f1 100644 --- a/test/uvw/fs_req.cpp +++ b/test/uvw/fs_req.cpp @@ -264,6 +264,16 @@ TEST(FsReq, RenameSync) { } +TEST(FsReq, CopyFile) { + // TODO +} + + +TEST(FsReq, CopyFileSync) { + // TODO +} + + TEST(FsReq, Access) { const std::string filename = std::string{TARGET_FS_REQ_DIR} + std::string{"/test.file"}; @@ -501,7 +511,7 @@ TEST(FsReq, SymlinkAndUnlink) { }); fileReq->on>([&fsReq, &filename, &linkname](const auto &, auto &) { - fsReq->symlink(filename, linkname, 0); + fsReq->symlink(filename, linkname); }); fileReq->on>([](const auto &, auto &request) { @@ -527,7 +537,7 @@ TEST(FsReq, SymlinkAndUnlinkSync) { ASSERT_TRUE(fileReq->openSync(filename, O_CREAT | O_RDWR | O_TRUNC, 0644)); ASSERT_TRUE(fileReq->closeSync()); - ASSERT_TRUE(fsReq->symlinkSync(filename, linkname, 0)); + ASSERT_TRUE(fsReq->symlinkSync(filename, linkname)); ASSERT_TRUE(fsReq->unlinkSync(linkname)); loop->run();