XS-libunievent

 view release on metacpan or  search on metacpan

libunievent/src/panda/unievent/Fs.cc  view on Meta::CPAN

    return {};
}

ex<void> Fs::utime (fd_t fd, double atime, double mtime) {
    UEFS_SYNC({
        uv_fs_futime(nullptr, &uvr, fd, atime, mtime, nullptr);
    }, {});
    return {};
}

ex<void> Fs::chown (string_view path, uid_t uid, gid_t gid) {
    UE_NULL_TERMINATE(path, path_str);
    UEFS_SYNC({
        uv_fs_chown(nullptr, &uvr, path_str, uid, gid, nullptr);
    }, {});
    return {};
}

ex<void> Fs::lchown (string_view path, uid_t uid, gid_t gid) {
    UE_NULL_TERMINATE(path, path_str);
    UEFS_SYNC({
        uv_fs_lchown(nullptr, &uvr, path_str, uid, gid, nullptr);
    }, {});
    return {};
}

ex<void> Fs::chown (fd_t fd, uid_t uid, gid_t gid) {
    UEFS_SYNC({
        uv_fs_fchown(nullptr, &uvr, fd, uid, gid, nullptr);
    }, {});
    return {};
}

ex<string> Fs::read (fd_t fd, size_t length, int64_t offset) {
    string ret;
    char* ptr = ret.reserve(length);
    uv_buf_t uvbuf;
    uvbuf.base = ptr;
    uvbuf.len  = length;

libunievent/src/panda/unievent/Fs.cc  view on Meta::CPAN

Fs::RequestSP Fs::unlink   (string_view path, const fn& cb, const LoopSP& l)                                    { UEFS_ASYNC_S(ret->unlink(path, cb)); }
Fs::RequestSP Fs::sync     (fd_t f, const fn& cb, const LoopSP& l)                                              { UEFS_ASYNC_SFD(ret->sync(cb)); }
Fs::RequestSP Fs::datasync (fd_t f, const fn& cb, const LoopSP& l)                                              { UEFS_ASYNC_SFD(ret->datasync(cb)); }
Fs::RequestSP Fs::truncate (string_view path, int64_t off, const fn& cb, const LoopSP& l)                       { UEFS_ASYNC_S(ret->truncate(path, off, cb)); }
Fs::RequestSP Fs::truncate (fd_t f, int64_t off, const fn& cb, const LoopSP& l)                                 { UEFS_ASYNC_SFD(ret->truncate(off, cb)); }
Fs::RequestSP Fs::chmod    (string_view path, int mode, const fn& cb, const LoopSP& l)                          { UEFS_ASYNC_S(ret->chmod(path, mode, cb)); }
Fs::RequestSP Fs::chmod    (fd_t f, int mode, const fn& cb, const LoopSP& l)                                    { UEFS_ASYNC_SFD(ret->chmod(mode, cb)); }
Fs::RequestSP Fs::touch    (string_view path, int mode, const fn& cb, const LoopSP& l)                          { UEFS_ASYNC_S(ret->touch(path, mode, cb)); }
Fs::RequestSP Fs::utime    (string_view path, double atime, double mtime, const fn& cb, const LoopSP& l)        { UEFS_ASYNC_S(ret->utime(path, atime, mtime, cb)); }
Fs::RequestSP Fs::utime    (fd_t f, double atime, double mtime, const fn& cb, const LoopSP& l)                  { UEFS_ASYNC_SFD(ret->utime(atime, mtime, cb)); }
Fs::RequestSP Fs::chown    (string_view path, uid_t uid, gid_t gid, const fn& cb, const LoopSP& l)              { UEFS_ASYNC_S(ret->chown(path, uid, gid, cb)); }
Fs::RequestSP Fs::lchown   (string_view path, uid_t uid, gid_t gid, const fn& cb, const LoopSP& l)              { UEFS_ASYNC_S(ret->lchown(path, uid, gid, cb)); }
Fs::RequestSP Fs::chown    (fd_t f, uid_t uid, gid_t gid, const fn& cb, const LoopSP& l)                        { UEFS_ASYNC_SFD(ret->chown(uid, gid, cb)); }
Fs::RequestSP Fs::rename   (string_view src, string_view dst, const fn& cb, const LoopSP& l)                    { UEFS_ASYNC_S(ret->rename(src, dst, cb)); }
Fs::RequestSP Fs::sendfile (fd_t out, fd_t in, int64_t off, size_t len, const sendfile_fn& cb, const LoopSP& l) { UEFS_ASYNC_S(ret->sendfile(out, in, off, len, cb)); }
Fs::RequestSP Fs::link     (string_view src, string_view dst, const fn& cb, const LoopSP& l)                    { UEFS_ASYNC_S(ret->link(src, dst, cb)); }
Fs::RequestSP Fs::symlink  (string_view src, string_view dst, int flags, const fn& cb, const LoopSP& l)         { UEFS_ASYNC_S(ret->symlink(src, dst, flags, cb)); }
Fs::RequestSP Fs::readlink (string_view path, const string_fn& cb, const LoopSP& l)                             { UEFS_ASYNC_S(ret->readlink(path, cb)); }
Fs::RequestSP Fs::realpath (string_view path, const string_fn& cb, const LoopSP& l)                             { UEFS_ASYNC_S(ret->realpath(path, cb)); }
Fs::RequestSP Fs::copyfile (string_view src, string_view dst, int flags, const fn& cb, const LoopSP& l)         { UEFS_ASYNC_S(ret->copyfile(src, dst, flags, cb)); }
Fs::RequestSP Fs::mkdtemp  (string_view path, const string_fn& cb, const LoopSP& l)                             { UEFS_ASYNC_S(ret->mkdtemp(path, cb)); }
Fs::RequestSP Fs::read     (fd_t f, size_t size, int64_t off, const string_fn& cb, const LoopSP& l)             { UEFS_ASYNC_SFD(ret->read(size, off, cb)); }
Fs::RequestSP Fs::_write   (fd_t f, std::vector<string>&& v, int64_t off, const fn& cb, const LoopSP& l)        { UEFS_ASYNC_SFD(ret->_write(std::move(v), off, cb)); }

libunievent/src/panda/unievent/Fs.cc  view on Meta::CPAN

void Fs::Request::unlink   (string_view _path, const fn& cb)                                   { auto path = string(_path); UEFS_ASYNC_VOID(Fs::unlink(path)); }
void Fs::Request::sync     (const fn& cb)                                                      { UEFS_ASYNC_VOID(Fs::sync(_fd)); }
void Fs::Request::datasync (const fn& cb)                                                      { UEFS_ASYNC_VOID(Fs::datasync(_fd)); }
void Fs::Request::truncate (string_view _path, int64_t off, const fn& cb)                      { auto path = string(_path); UEFS_ASYNC_VOID(Fs::truncate(path, off)); }
void Fs::Request::truncate (int64_t off, const fn& cb)                                         { UEFS_ASYNC_VOID(Fs::truncate(_fd, off)); }
void Fs::Request::chmod    (string_view _path, int mode, const fn& cb)                         { auto path = string(_path); UEFS_ASYNC_VOID(Fs::chmod(path, mode)); }
void Fs::Request::chmod    (int mode, const fn& cb)                                            { UEFS_ASYNC_VOID(Fs::chmod(_fd, mode)); }
void Fs::Request::touch    (string_view _path, int mode, const fn& cb)                         { auto path = string(_path); UEFS_ASYNC_VOID(Fs::touch(path, mode)); }
void Fs::Request::utime    (string_view _path, double atime, double mtime, const fn& cb)       { auto path = string(_path); UEFS_ASYNC_VOID(Fs::utime(path, atime, mtime)); }
void Fs::Request::utime    (double atime, double mtime, const fn& cb)                          { UEFS_ASYNC_VOID(Fs::utime(_fd, atime, mtime)); }
void Fs::Request::chown    (string_view _path, uid_t uid, gid_t gid, const fn& cb)             { auto path = string(_path); UEFS_ASYNC_VOID(Fs::chown(path, uid, gid)); }
void Fs::Request::lchown   (string_view _path, uid_t uid, gid_t gid, const fn& cb)             { auto path = string(_path); UEFS_ASYNC_VOID(Fs::lchown(path, uid, gid)); }
void Fs::Request::chown    (uid_t uid, gid_t gid, const fn& cb)                                { UEFS_ASYNC_VOID(Fs::chown(_fd, uid, gid)); }
void Fs::Request::rename   (string_view _src, string_view _dst, const fn& cb)                  { auto src = string(_src); auto dst = string(_dst); UEFS_ASYNC_VOID(Fs::rename(src, dst)); }
void Fs::Request::sendfile (fd_t out, fd_t in, int64_t off, size_t len, const sendfile_fn& cb) { UEFS_ASYNC(Fs::sendfile(out, in, off, len), (_size = *ret), cb(_size, _err, this)); }
void Fs::Request::link     (string_view _src, string_view _dst, const fn& cb)                  { auto src = string(_src); auto dst = string(_dst); UEFS_ASYNC_VOID(Fs::link(src, dst)); }
void Fs::Request::symlink  (string_view _src, string_view _dst, int flags, const fn& cb)       { auto src = string(_src); auto dst = string(_dst); UEFS_ASYNC_VOID(Fs::symlink(src, dst, flags)); }
void Fs::Request::readlink (string_view _path, const string_fn& cb)                            { auto path = string(_path); UEFS_ASYNC_STR(Fs::readlink(path)); }
void Fs::Request::realpath (string_view _path, const string_fn& cb)                            { auto path = string(_path); UEFS_ASYNC_STR(Fs::realpath(path)); }
void Fs::Request::copyfile (string_view _src, string_view _dst, int flags, const fn& cb)       { auto src = string(_src); auto dst = string(_dst); UEFS_ASYNC_VOID(Fs::copyfile(src, dst, flags)); }
void Fs::Request::mkdtemp  (string_view _path, const string_fn& cb)                            { auto path = string(_path); UEFS_ASYNC_STR(Fs::mkdtemp(path)); }
void Fs::Request::read     (size_t size, int64_t off, const string_fn& cb)                     { UEFS_ASYNC_STR(Fs::read(_fd, size, off)); }
void Fs::Request::_write   (std::vector<string>&& v, int64_t off, const fn& cb)                {

libunievent/src/panda/unievent/Fs.h  view on Meta::CPAN

    static ex<void>       unlink   (string_view);
    static ex<void>       sync     (fd_t);
    static ex<void>       datasync (fd_t);
    static ex<void>       truncate (string_view, int64_t length = 0);
    static ex<void>       truncate (fd_t, int64_t length = 0);
    static ex<void>       chmod    (string_view, int mode);
    static ex<void>       chmod    (fd_t,        int mode);
    static ex<void>       touch    (string_view, int mode = DEFAULT_FILE_MODE);
    static ex<void>       utime    (string_view, double atime, double mtime);
    static ex<void>       utime    (fd_t,        double atime, double mtime);
    static ex<void>       chown    (string_view, uid_t uid, gid_t gid);
    static ex<void>       lchown   (string_view, uid_t uid, gid_t gid);
    static ex<void>       chown    (fd_t,        uid_t uid, gid_t gid);
    static ex<void>       rename   (string_view src, string_view dst);
    static ex<size_t>     sendfile (fd_t out, fd_t in, int64_t offset, size_t length);
    static ex<void>       link     (string_view src, string_view dst);
    static ex<void>       symlink  (string_view src, string_view dst, int flags = 0);
    static ex<string>     readlink (string_view);
    static ex<string>     realpath (string_view);
    static ex<void>       copyfile (string_view src, string_view dst, int flags = 0);
    static ex<string>     mkdtemp  (string_view);
    static ex<string>     read     (fd_t, size_t length, int64_t offset = -1);
    static ex<void>       write    (fd_t fd, const string_view& buf, int64_t offset = -1) { return write(fd, &buf, &buf+1, offset); }

libunievent/src/panda/unievent/Fs.h  view on Meta::CPAN

    static RequestSP unlink   (string_view, const fn&, const LoopSP& = Loop::default_loop());
    static RequestSP sync     (fd_t, const fn&, const LoopSP& = Loop::default_loop());
    static RequestSP datasync (fd_t, const fn&, const LoopSP& = Loop::default_loop());
    static RequestSP truncate (string_view, int64_t offset, const fn&, const LoopSP& = Loop::default_loop());
    static RequestSP truncate (fd_t, int64_t offset, const fn&, const LoopSP& = Loop::default_loop());
    static RequestSP chmod    (string_view, int mode, const fn&, const LoopSP& = Loop::default_loop());
    static RequestSP chmod    (fd_t, int mode, const fn&, const LoopSP& = Loop::default_loop());
    static RequestSP touch    (string_view, int mode, const fn&, const LoopSP& = Loop::default_loop());
    static RequestSP utime    (string_view, double atime, double mtime, const fn&, const LoopSP& = Loop::default_loop());
    static RequestSP utime    (fd_t, double atime, double mtime, const fn&, const LoopSP& = Loop::default_loop());
    static RequestSP chown    (string_view, uid_t uid, gid_t gid, const fn&, const LoopSP& = Loop::default_loop());
    static RequestSP lchown   (string_view, uid_t uid, gid_t gid, const fn&, const LoopSP& = Loop::default_loop());
    static RequestSP chown    (fd_t, uid_t uid, gid_t gid, const fn&, const LoopSP& = Loop::default_loop());
    static RequestSP rename   (string_view src, string_view dst, const fn&, const LoopSP& = Loop::default_loop());
    static RequestSP sendfile (fd_t out, fd_t in, int64_t offset, size_t length, const sendfile_fn&, const LoopSP& = Loop::default_loop());
    static RequestSP link     (string_view src, string_view dst, const fn&, const LoopSP& = Loop::default_loop());
    static RequestSP symlink  (string_view src, string_view dst, int flags, const fn&, const LoopSP& = Loop::default_loop());
    static RequestSP readlink (string_view, const string_fn&, const LoopSP& = Loop::default_loop());
    static RequestSP realpath (string_view, const string_fn&, const LoopSP& = Loop::default_loop());
    static RequestSP copyfile (string_view src, string_view dst, int flags, const fn&, const LoopSP& = Loop::default_loop());
    static RequestSP mkdtemp  (string_view, const string_fn&, const LoopSP& = Loop::default_loop());
    static RequestSP read     (fd_t, size_t size, int64_t offset, const string_fn&, const LoopSP& = Loop::default_loop());
    static RequestSP write    (fd_t fd, const string_view& buf, int64_t offset, const fn& cb, const LoopSP& loop) { return _write(fd, {string(buf)}, offset, cb, loop); }

libunievent/src/panda/unievent/Fs.h  view on Meta::CPAN

        void unlink   (string_view, const fn&);
        void sync     (const fn&);
        void datasync (const fn&);
        void truncate (string_view, int64_t offset, const fn&);
        void truncate (int64_t offset, const fn&);
        void chmod    (string_view, int mode, const fn&);
        void chmod    (int mode, const fn&);
        void touch    (string_view, int mode, const fn&);
        void utime    (string_view, double atime, double mtime, const fn&);
        void utime    (double atime, double mtime, const fn&);
        void chown    (string_view, uid_t uid, gid_t gid, const fn&);
        void lchown   (string_view, uid_t uid, gid_t gid, const fn&);
        void chown    (uid_t uid, gid_t gid, const fn&);
        void rename   (string_view src, string_view dst, const fn&);
        void sendfile (fd_t out, fd_t in, int64_t offset, size_t length, const sendfile_fn&);
        void link     (string_view src, string_view dst, const fn&);
        void symlink  (string_view src, string_view dst, int flags, const fn&);
        void readlink (string_view, const string_fn&);
        void realpath (string_view, const string_fn&);
        void copyfile (string_view src, string_view dst, int flags, const fn&);
        void mkdtemp  (string_view, const string_fn&);
        void read     (size_t size, int64_t offset, const string_fn&);

libunievent/tests/fs.cc  view on Meta::CPAN

            SECTION("fd") {
            Fs::touch(file);
            auto fd = Fs::open(file, Fs::OpenFlags::RDONLY).value();
            CHECK(Fs::utime(fd, 2000, 2000));
            Fs::close(fd);
            CHECK(Fs::stat(file).value().atime.get() == 2000);
            CHECK(Fs::stat(file).value().mtime.get() == 2000);
        }
    }

    // no tests for chown

    SECTION("rename") {
        SECTION("non-existant") {
            Fs::touch(file2);
            auto ret = Fs::rename(file, file2);
            REQUIRE(!ret);
            CHECK(ret.error() == std::errc::no_such_file_or_directory);
        }
        SECTION("exists file") {
            Fs::touch(file);

libunievent/tests/fs.cc  view on Meta::CPAN

        SECTION("fd") {
            auto fd = Fs::open(file, Fs::OpenFlags::RDONLY).value();
            Fs::utime(fd, 2000, 2000, success, l);
            l->run();
            Fs::close(fd);
            CHECK(Fs::stat(file).value().atime.get() == 2000);
            CHECK(Fs::stat(file).value().mtime.get() == 2000);
        }
    }

    // no tests for chown

    SECTION("rename") {
        Fs::touch(file);
        Fs::rename(file, file2, success, l);
        l->run();
        CHECK(!Fs::exists(file));
        CHECK(Fs::isfile(file2));
    }

    l->run();



( run in 1.003 second using v1.01-cache-2.11-cpan-5511b514fd6 )