Skip to content

Commit

Permalink
now working with libuv 1.14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Aug 18, 2017
1 parent 383182e commit a05733d
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cmake/in/libuv.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
136 changes: 116 additions & 20 deletions src/uvw/fs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ enum class UVFsType: std::underlying_type_t<uv_fs_type> {
READLINK = UV_FS_READLINK,
CHOWN = UV_FS_CHOWN,
FCHOWN = UV_FS_FCHOWN,
REALPATH = UV_FS_REALPATH
REALPATH = UV_FS_REALPATH,
COPYFILE = UV_FS_COPYFILE
};


Expand All @@ -63,6 +64,17 @@ enum class UVDirentTypeT: std::underlying_type_t<uv_dirent_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
};


}


Expand Down Expand Up @@ -101,6 +113,7 @@ enum class UVDirentTypeT: std::underlying_type_t<uv_dirent_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.
Expand Down Expand Up @@ -696,6 +709,20 @@ class FileReq final: public FsRequest<FileReq> {
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.<br/>
* 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.
*
Expand Down Expand Up @@ -733,6 +760,9 @@ class FsReq final: public FsRequest<FsReq> {
}

public:
using CopyFile = details::UVCopyFileFlags;
using SymLink = details::UVSymLinkFlags;

using FsRequest::FsRequest;

~FsReq() noexcept {
Expand All @@ -742,7 +772,7 @@ class FsReq final: public FsRequest<FsReq> {
/**
* @brief Async [unlink](http://linux.die.net/man/2/unlink).
*
* Emit a `FsEvent<FileReq::Type::UNLINK>` event when completed.<br/>
* Emit a `FsEvent<FsReq::Type::UNLINK>` event when completed.<br/>
* Emit an ErrorEvent event in case of errors.
*
* @param path Path, as described in the official documentation.
Expand All @@ -765,7 +795,7 @@ class FsReq final: public FsRequest<FsReq> {
/**
* @brief Async [mkdir](http://linux.die.net/man/2/mkdir).
*
* Emit a `FsEvent<FileReq::Type::MKDIR>` event when completed.<br/>
* Emit a `FsEvent<FsReq::Type::MKDIR>` event when completed.<br/>
* Emit an ErrorEvent event in case of errors.
*
* @param path Path, as described in the official documentation.
Expand All @@ -790,7 +820,7 @@ class FsReq final: public FsRequest<FsReq> {
/**
* @brief Async [mktemp](http://linux.die.net/man/3/mkdtemp).
*
* Emit a `FsEvent<FileReq::Type::MKDTEMP>` event when completed.<br/>
* Emit a `FsEvent<FsReq::Type::MKDTEMP>` event when completed.<br/>
* Emit an ErrorEvent event in case of errors.
*
* @param tpl Template, as described in the official documentation.
Expand All @@ -817,7 +847,7 @@ class FsReq final: public FsRequest<FsReq> {
/**
* @brief Async [rmdir](http://linux.die.net/man/2/rmdir).
*
* Emit a `FsEvent<FileReq::Type::RMDIR>` event when completed.<br/>
* Emit a `FsEvent<FsReq::Type::RMDIR>` event when completed.<br/>
* Emit an ErrorEvent event in case of errors.
*
* @param path Path, as described in the official documentation.
Expand All @@ -840,7 +870,7 @@ class FsReq final: public FsRequest<FsReq> {
/**
* @brief Async [scandir](http://linux.die.net/man/3/scandir).
*
* Emit a `FsEvent<FileReq::Type::SCANDIR>` event when completed.<br/>
* Emit a `FsEvent<FsReq::Type::SCANDIR>` event when completed.<br/>
* Emit an ErrorEvent event in case of errors.
*
* @param path Path, as described in the official documentation.
Expand Down Expand Up @@ -913,7 +943,7 @@ class FsReq final: public FsRequest<FsReq> {
/**
* @brief Async [stat](http://linux.die.net/man/2/stat).
*
* Emit a `FsEvent<FileReq::Type::STAT>` event when completed.<br/>
* Emit a `FsEvent<FsReq::Type::STAT>` event when completed.<br/>
* Emit an ErrorEvent event in case of errors.
*
* @param path Path, as described in the official documentation.
Expand All @@ -940,7 +970,7 @@ class FsReq final: public FsRequest<FsReq> {
/**
* @brief Async [lstat](http://linux.die.net/man/2/lstat).
*
* Emit a `FsEvent<FileReq::Type::LSTAT>` event when completed.<br/>
* Emit a `FsEvent<FsReq::Type::LSTAT>` event when completed.<br/>
* Emit an ErrorEvent event in case of errors.
*
* @param path Path, as described in the official documentation.
Expand All @@ -967,7 +997,7 @@ class FsReq final: public FsRequest<FsReq> {
/**
* @brief Async [rename](http://linux.die.net/man/2/rename).
*
* Emit a `FsEvent<FileReq::Type::RENAME>` event when completed.<br/>
* Emit a `FsEvent<FsReq::Type::RENAME>` event when completed.<br/>
* Emit an ErrorEvent event in case of errors.
*
* @param old Old path, as described in the official documentation.
Expand All @@ -989,10 +1019,61 @@ class FsReq final: public FsRequest<FsReq> {
return !(req->result < 0);
}

/**
* @brief Copies a file asynchronously from a path to a new one.
*
* Emit a `FsEvent<FsReq::Type::UV_FS_COPYFILE>` event when
* completed.<br/>
* 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<CopyFile> flags = Flags<CopyFile>{}) {
cleanupAndInvoke(&uv_fs_copyfile, parent(), get(), old.data(), path.data(), flags, &fsGenericCallback<Type::COPYFILE>);
}

/**
* @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<CopyFile> flags = Flags<CopyFile>{}) {
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<FileReq::Type::ACCESS>` event when completed.<br/>
* Emit a `FsEvent<FsReq::Type::ACCESS>` event when completed.<br/>
* Emit an ErrorEvent event in case of errors.
*
* @param path Path, as described in the official documentation.
Expand All @@ -1017,7 +1098,7 @@ class FsReq final: public FsRequest<FsReq> {
/**
* @brief Async [chmod](http://linux.die.net/man/2/chmod).
*
* Emit a `FsEvent<FileReq::Type::CHMOD>` event when completed.<br/>
* Emit a `FsEvent<FsReq::Type::CHMOD>` event when completed.<br/>
* Emit an ErrorEvent event in case of errors.
*
* @param path Path, as described in the official documentation.
Expand All @@ -1042,7 +1123,7 @@ class FsReq final: public FsRequest<FsReq> {
/**
* @brief Async [utime](http://linux.die.net/man/2/utime).
*
* Emit a `FsEvent<FileReq::Type::UTIME>` event when completed.<br/>
* Emit a `FsEvent<FsReq::Type::UTIME>` event when completed.<br/>
* Emit an ErrorEvent event in case of errors.
*
* @param path Path, as described in the official documentation.
Expand Down Expand Up @@ -1073,7 +1154,7 @@ class FsReq final: public FsRequest<FsReq> {
/**
* @brief Async [link](http://linux.die.net/man/2/link).
*
* Emit a `FsEvent<FileReq::Type::LINK>` event when completed.<br/>
* Emit a `FsEvent<FsReq::Type::LINK>` event when completed.<br/>
* Emit an ErrorEvent event in case of errors.
*
* @param old Old path, as described in the official documentation.
Expand All @@ -1098,25 +1179,40 @@ class FsReq final: public FsRequest<FsReq> {
/**
* @brief Async [symlink](http://linux.die.net/man/2/symlink).
*
* Emit a `FsEvent<FileReq::Type::SYMLINK>` event when completed.<br/>
* Emit a `FsEvent<FsReq::Type::SYMLINK>` event when completed.<br/>
* 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<SymLink> flags = Flags<SymLink>{}) {
cleanupAndInvoke(&uv_fs_symlink, parent(), get(), old.data(), path.data(), flags, &fsGenericCallback<Type::SYMLINK>);
}

/**
* @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<SymLink> flags = Flags<SymLink>{}) {
auto req = get();
cleanupAndInvokeSync(&uv_fs_symlink, parent(), req, old.data(), path.data(), flags);
return !(req->result < 0);
Expand All @@ -1125,7 +1221,7 @@ class FsReq final: public FsRequest<FsReq> {
/**
* @brief Async [readlink](http://linux.die.net/man/2/readlink).
*
* Emit a `FsEvent<FileReq::Type::READLINK>` event when completed.<br/>
* Emit a `FsEvent<FsReq::Type::READLINK>` event when completed.<br/>
* Emit an ErrorEvent event in case of errors.
*
* @param path Path, as described in the official documentation.
Expand Down Expand Up @@ -1156,7 +1252,7 @@ class FsReq final: public FsRequest<FsReq> {
/**
* @brief Async [realpath](http://linux.die.net/man/3/realpath).
*
* Emit a `FsEvent<FileReq::Type::REALPATH>` event when completed.<br/>
* Emit a `FsEvent<FsReq::Type::REALPATH>` event when completed.<br/>
* Emit an ErrorEvent event in case of errors.
*
* @param path Path, as described in the official documentation.
Expand All @@ -1183,7 +1279,7 @@ class FsReq final: public FsRequest<FsReq> {
/**
* @brief Async [chown](http://linux.die.net/man/2/chown).
*
* Emit a `FsEvent<FileReq::Type::CHOWN>` event when completed.<br/>
* Emit a `FsEvent<FsReq::Type::CHOWN>` event when completed.<br/>
* Emit an ErrorEvent event in case of errors.
*
* @param path Path, as described in the official documentation.
Expand Down
6 changes: 5 additions & 1 deletion src/uvw/poll.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ namespace details {
enum class UVPollEvent: std::underlying_type_t<uv_poll_event> {
READABLE = UV_READABLE,
WRITABLE = UV_WRITABLE,
DISCONNECT = UV_DISCONNECT
DISCONNECT = UV_DISCONNECT,
PRIORITIZED = UV_PRIORITIZED
};


Expand All @@ -43,6 +44,7 @@ struct PollEvent {
* * `PollHandle::Event::READABLE`
* * `PollHandle::Event::WRITABLE`
* * `PollHandle::Event::DISCONNECT`
* * `PollHandle::Event::PRIORITIZED`
*/
Flags<details::UVPollEvent> flags;
};
Expand Down Expand Up @@ -100,6 +102,7 @@ class PollHandle final: public Handle<PollHandle, uv_poll_t> {
* * `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.<br>
Expand All @@ -122,6 +125,7 @@ class PollHandle final: public Handle<PollHandle, uv_poll_t> {
* * `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.<br>
Expand Down
14 changes: 12 additions & 2 deletions test/uvw/fs_req.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"};

Expand Down Expand Up @@ -501,7 +511,7 @@ TEST(FsReq, SymlinkAndUnlink) {
});

fileReq->on<uvw::FsEvent<uvw::FileReq::Type::CLOSE>>([&fsReq, &filename, &linkname](const auto &, auto &) {
fsReq->symlink(filename, linkname, 0);
fsReq->symlink(filename, linkname);
});

fileReq->on<uvw::FsEvent<uvw::FileReq::Type::OPEN>>([](const auto &, auto &request) {
Expand All @@ -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();
Expand Down

0 comments on commit a05733d

Please sign in to comment.