Example #1
0
def scandir(path):
    path = pathobj.os_stringify(path).encode('utf-8')
    req = lltype.malloc(uv.fs_ptr.TO, flavor='raw', zero=True)
    dirent = lltype.malloc(uv.dirent_ptr.TO, flavor='raw', zero=True)
    try:
        response = uv_callback.fs(req)
        response.wait(
            uv.fs_scandir(
                response.ec.uv_loop,
                req,
                path,
                0,  # TODO: check if there are meaningful flags for this.
                uv_callback.fs.cb))
        if req.c_result < 0:
            raise uv_callback.to_error(req.c_result)
        listing = []
        while True:
            res = uv.fs_scandir_next(req, dirent)
            if res == uv.EOF:
                break
            elif res < 0:
                raise uv_callback.to_error(res)
            entry = Exnihilo()
            entry.setattr(u"path", from_cstring(rffi.charp2str(dirent.c_name)))
            if dirent.c_type in uv.dirent2name:
                entry.setattr(u"type", String(uv.dirent2name[dirent.c_type]))
            else:
                entry.setattr(u"type", Integer(rffi.r_long(dirent.c_type)))
            listing.append(entry)
        return List(listing)
    finally:
        uv.fs_req_cleanup(req)
        lltype.free(dirent, flavor='raw')
        lltype.free(req, flavor='raw')
Example #2
0
def File_fsync(self):
    req = lltype.malloc(uv.fs_ptr.TO, flavor='raw', zero=True)
    try:
        response = uv_callback.fs(req)
        response.wait(
            uv.fs_fsync(response.ec.uv_loop, req, self.fd, uv_callback.fs.cb))
        if req.c_result < 0:
            raise uv_callback.to_error(req.c_result)
        return null
    finally:
        uv.fs_req_cleanup(req)
        lltype.free(req, flavor='raw')
Example #3
0
def sendfile(out_file, in_file, in_offset, length):
    req = lltype.malloc(uv.fs_ptr.TO, flavor='raw', zero=True)
    try:
        response = uv_callback.fs(req)
        response.wait(
            uv.fs_sendfile(response.ec.uv_loop, req, out_file.fd, in_file.fd,
                           in_offset.value, length.value, uv_callback.fs.cb))
        if req.c_result < 0:
            raise uv_callback.to_error(req.c_result)
        return Integer(rffi.r_long(req.c_result))
    finally:
        uv.fs_req_cleanup(req)
        lltype.free(req, flavor='raw')
Example #4
0
def lstat(path):
    path = pathobj.os_stringify(path).encode('utf-8')
    req = lltype.malloc(uv.fs_ptr.TO, flavor='raw', zero=True)
    try:
        response = uv_callback.fs(req)
        response.wait(
            uv.fs_lstat(response.ec.uv_loop, req, path, uv_callback.fs.cb))
        if req.c_result < 0:
            raise uv_callback.to_error(req.c_result)
        return stat2data(req.c_statbuf)
    finally:
        uv.fs_req_cleanup(req)
        lltype.free(req, flavor='raw')
Example #5
0
def chown(path, uid, gid):
    path = pathobj.os_stringify(path).encode('utf-8')
    req = lltype.malloc(uv.fs_ptr.TO, flavor='raw', zero=True)
    try:
        response = uv_callback.fs(req)
        response.wait(
            uv.fs_chown(response.ec.uv_loop, req, path, uid.value, gid.value,
                        uv_callback.fs.cb))
        if req.c_result < 0:
            raise uv_callback.to_error(req.c_result)
        return null
    finally:
        uv.fs_req_cleanup(req)
        lltype.free(req, flavor='raw')
Example #6
0
def realpath(path):
    path = pathobj.os_stringify(path).encode('utf-8')
    req = lltype.malloc(uv.fs_ptr.TO, flavor='raw', zero=True)
    try:
        response = uv_callback.fs(req)
        response.wait(
            uv.fs_realpath(response.ec.uv_loop, req, path, uv_callback.fs.cb))
        if req.c_result < 0:
            raise uv_callback.to_error(req.c_result)
        # hmm?
        return from_cstring(rffi.charp2str(rffi.cast(rffi.CCHARP, req.c_ptr)))
    finally:
        uv.fs_req_cleanup(req)
        lltype.free(req, flavor='raw')
Example #7
0
def mkdtemp(path):
    path = pathobj.os_stringify(path).encode('utf-8')
    # TODO: XXXXXX  the last six characters must be these.
    req = lltype.malloc(uv.fs_ptr.TO, flavor='raw', zero=True)
    try:
        response = uv_callback.fs(req)
        response.wait(
            uv.fs_mkdtemp(response.ec.uv_loop, req, path, uv_callback.fs.cb))
        if req.c_result < 0:
            raise uv_callback.to_error(req.c_result)
        return from_cstring(rffi.charp2str(rffi.cast(rffi.CCHARP, req.c_path)))
    finally:
        uv.fs_req_cleanup(req)
        lltype.free(req, flavor='raw')
Example #8
0
def mkdir(path, mode):
    mode = 0777 if mode is None else mode.value
    path = pathobj.os_stringify(path).encode('utf-8')
    req = lltype.malloc(uv.fs_ptr.TO, flavor='raw', zero=True)
    try:
        response = uv_callback.fs(req)
        response.wait(
            uv.fs_mkdir(response.ec.uv_loop, req, path, mode,
                        uv_callback.fs.cb))
        if req.c_result < 0:
            raise uv_callback.to_error(req.c_result)
        return null
    finally:
        uv.fs_req_cleanup(req)
        lltype.free(req, flavor='raw')
Example #9
0
def File_pwrite(self, data, offset):
    bufs, nbufs = uv_callback.obj2bufs(data)
    req = lltype.malloc(uv.fs_ptr.TO, flavor='raw', zero=True)
    try:
        response = uv_callback.fs(req)
        response.wait(
            uv.fs_write(response.ec.uv_loop, req, self.fd, bufs, nbufs,
                        offset.value, uv_callback.fs.cb))
        if req.c_result < 0:
            raise uv_callback.to_error(req.c_result)
        return Integer(rffi.r_long(req.c_result))
    finally:
        uv.fs_req_cleanup(req)
        lltype.free(bufs, flavor='raw')
        lltype.free(req, flavor='raw')
Example #10
0
def open_(path, flags, mode):
    mode = 0664 if mode is None else mode.value
    path = pathobj.os_stringify(path).encode('utf-8')
    req = lltype.malloc(uv.fs_ptr.TO, flavor='raw', zero=True)
    try:
        response = uv_callback.fs(req)
        response.wait(
            uv.fs_open(response.ec.uv_loop, req, path, flags.value, mode,
                       uv_callback.fs.cb))
        if req.c_result < 0:
            raise uv_callback.to_error(req.c_result)
        return File(rffi.r_long(req.c_result))
    finally:
        uv.fs_req_cleanup(req)
        lltype.free(req, flavor='raw')
Example #11
0
def symlink(path, new_path):
    path = pathobj.os_stringify(path).encode('utf-8')
    new_path = pathobj.os_stringify(new_path).encode('utf-8')
    req = lltype.malloc(uv.fs_ptr.TO, flavor='raw', zero=True)
    try:
        response = uv_callback.fs(req)
        response.wait(
            uv.fs_symlink(
                response.ec.uv_loop,
                req,
                path,
                new_path,
                0,  # TODO: FS_SYMLINK_DIR, FS_SYMLINK_JUNCTION -flags.
                uv_callback.fs.cb))
        if req.c_result < 0:
            raise uv_callback.to_error(req.c_result)
        return null
    finally:
        uv.fs_req_cleanup(req)
        lltype.free(req, flavor='raw')