예제 #1
0
파일: streamcaps.py 프로젝트: dckc/typhon
    def __init__(self, fs, fd, vat):
        self._fs = fs
        self._fd = fd
        self._vat = vat

        # Set this up only once.
        ruv.stashFS(fs, (vat, self))
예제 #2
0
    def run(self, data):
        if self.closed:
            raise userError(u"run/1: Couldn't write to closged file")

        sb = ruv.scopedBufs([data], self)
        bufs = sb.allocate()
        fs = ruv.alloc_fs()
        ruv.stashFS(fs, (self._vat, sb))
        ruv.fsWrite(self._vat.uv_loop, fs, self._fd, bufs, 1, -1, writeFileCB)
예제 #3
0
파일: files.py 프로젝트: dckc/typhon
    def __init__(self, fs, fd, vat):
        self.fs = fs
        self.fd = fd
        self.vat = vat

        self.bufs = []

        # Set this up only once.
        ruv.stashFS(self.fs, (self.vat, self))
예제 #4
0
    def __init__(self, fs, fd, vat):
        self.fs = fs
        self.fd = fd
        self.vat = vat

        self.bufs = []

        # Set this up only once.
        ruv.stashFS(self.fs, (self.vat, self))
예제 #5
0
    def rename(self, dest):
        p, r = makePromise()
        vat = currentVat.get()
        uv_loop = vat.uv_loop
        fs = ruv.alloc_fs()

        src = self.asBytes()
        ruv.stashFS(fs, (vat, r))
        ruv.fsRename(uv_loop, fs, src, dest, renameCB)
        return p
예제 #6
0
파일: files.py 프로젝트: dckc/typhon
    def rename(self, dest):
        p, r = makePromise()
        vat = currentVat.get()
        uv_loop = vat.uv_loop
        fs = ruv.alloc_fs()

        src = self.asBytes()
        ruv.stashFS(fs, (vat, r))
        ruv.fsRename(uv_loop, fs, src, dest, renameCB)
        return p
예제 #7
0
    def __init__(self, fs, fd, vat):
        self.fs = fs
        self.fd = fd
        self.vat = vat

        # XXX read size should be tunable
        self.buf = ruv.allocBuf(16384)

        # Set this up only once.
        ruv.stashFS(self.fs, (self.vat, self))
예제 #8
0
파일: files.py 프로젝트: dckc/typhon
    def __init__(self, fs, fd, vat):
        self.fs = fs
        self.fd = fd
        self.vat = vat

        # XXX read size should be tunable
        self.buf = ruv.allocBuf(16384)

        # Set this up only once.
        ruv.stashFS(self.fs, (self.vat, self))
예제 #9
0
 def run(self, sink):
     p, r = makePromise()
     self._queue.append((r, sink))
     with scoped_alloc(ruv.rffi.CArray(ruv.buf_t), 1) as bufs:
         bufs[0].c_base = self._buf.c_base
         bufs[0].c_len = self._buf.c_len
         fs = ruv.alloc_fs()
         ruv.stashFS(fs, (self._vat, self))
         ruv.fsRead(self._vat.uv_loop, fs, self._fd, bufs, 1, -1,
                    readFileCB)
     return p
예제 #10
0
파일: streamcaps.py 프로젝트: dckc/typhon
    def __init__(self, fs, fd, vat):
        self._fs = fs
        self._fd = fd
        self._vat = vat

        self._queue = []

        # XXX read size should be tunable
        self._buf = ruv.allocBuf(16384)

        # Set this up only once.
        ruv.stashFS(fs, (vat, self))
예제 #11
0
파일: files.py 프로젝트: dckc/typhon
    def __init__(self, vat, fs, fd, resolver):
        self.vat = vat
        self.fs = fs
        self.fd = fd
        self.resolver = resolver

        self.pieces = []

        # XXX read size should be tunable
        self.buf = ruv.allocBuf(16384)

        # Do our initial stashing.
        ruv.stashFS(fs, (vat, self))
예제 #12
0
    def __init__(self, vat, fs, fd, resolver):
        self.vat = vat
        self.fs = fs
        self.fd = fd
        self.resolver = resolver

        self.pieces = []

        # XXX read size should be tunable
        self.buf = ruv.allocBuf(16384)

        # Do our initial stashing.
        ruv.stashFS(fs, (vat, self))
예제 #13
0
    def recv(self, atom, args):
        if atom is GETCONTENTS_0:
            return self.open(openGetContentsCB, flags=os.O_RDONLY, mode=0000)

        if atom is SETCONTENTS_1:
            data = unwrapBytes(args[0])
            sibling = self.temporarySibling(".setContents")

            p, r = makePromise()
            vat = currentVat.get()
            uv_loop = vat.uv_loop
            fs = ruv.alloc_fs()

            path = sibling.asBytes()
            # Use CREAT | EXCL to cause a failure if the temporary file
            # already exists.
            flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL
            sc = SetContents(vat, data, r, sibling, self)
            ruv.stashFS(fs, (vat, sc))
            ruv.fsOpen(uv_loop, fs, path, flags, 0777, openSetContentsCB)
            return p

        if atom is OPENFOUNT_0:
            return self.open(openFountCB, flags=os.O_RDONLY, mode=0000)

        if atom is OPENDRAIN_0:
            # Create the file if it doesn't yet exist, and truncate it if it
            # does. Trust the umask to be reasonable for now.
            flags = os.O_CREAT | os.O_WRONLY
            # XXX this behavior should be configurable via namedarg?
            flags |= os.O_TRUNC
            return self.open(openDrainCB, flags=flags, mode=0777)

        if atom is RENAME_1:
            fr = args[0]
            if not isinstance(fr, FileResource):
                raise userError(u"rename/1: Must be file resource")
            return self.rename(fr.asBytes())

        if atom is SIBLING_1:
            name = unwrapStr(args[0])
            if u'/' in name:
                raise userError(u"sibling/1: Illegal file name '%s'" % name)
            return self.sibling(name.encode("utf-8"))

        if atom is TEMPORARYSIBLING_0:
            return self.temporarySibling(".new")

        raise Refused(self, atom, args)
예제 #14
0
    def recv(self, atom, args):
        if atom is GETCONTENTS_0:
            return self.open(openGetContentsCB, flags=os.O_RDONLY, mode=0000)

        if atom is SETCONTENTS_1:
            data = unwrapBytes(args[0])
            sibling = self.temporarySibling(".setContents")

            p, r = makePromise()
            vat = currentVat.get()
            uv_loop = vat.uv_loop
            fs = ruv.alloc_fs()

            path = sibling.asBytes()
            # Use CREAT | EXCL to cause a failure if the temporary file
            # already exists.
            flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL
            sc = SetContents(vat, data, r, sibling, self)
            ruv.stashFS(fs, (vat, sc))
            ruv.fsOpen(uv_loop, fs, path, flags, 0777, openSetContentsCB)
            return p

        if atom is OPENFOUNT_0:
            return self.open(openFountCB, flags=os.O_RDONLY, mode=0000)

        if atom is OPENDRAIN_0:
            # Create the file if it doesn't yet exist, and truncate it if it
            # does. Trust the umask to be reasonable for now.
            flags = os.O_CREAT | os.O_WRONLY
            # XXX this behavior should be configurable via namedarg?
            flags |= os.O_TRUNC
            return self.open(openDrainCB, flags=flags, mode=0777)

        if atom is RENAME_1:
            fr = args[0]
            if not isinstance(fr, FileResource):
                raise userError(u"rename/1: Must be file resource")
            return self.rename(fr.asBytes())

        if atom is SIBLING_1:
            name = unwrapStr(args[0])
            if u'/' in name:
                raise userError(u"sibling/1: Illegal file name '%s'" % name)
            return self.sibling(name.encode("utf-8"))

        if atom is TEMPORARYSIBLING_0:
            return self.temporarySibling(".new")

        raise Refused(self, atom, args)
예제 #15
0
파일: files.py 프로젝트: dckc/typhon
    def open(self, callback, flags=None, mode=None):
        # Always call this as .open(callback, flags=..., mode=...)
        assert flags is not None
        assert mode is not None

        p, r = makePromise()
        vat = currentVat.get()
        uv_loop = vat.uv_loop
        fs = ruv.alloc_fs()

        path = self.asBytes()
        log.log(["fs"], u"makeFileResource: Opening file '%s'" % path.decode("utf-8"))
        ruv.stashFS(fs, (vat, r))
        ruv.fsOpen(uv_loop, fs, path, flags, mode, callback)
        return p
예제 #16
0
파일: files.py 프로젝트: dckc/typhon
    def setContents(self, data):
        sibling = self.temporarySibling(".setContents")

        p, r = makePromise()
        vat = currentVat.get()
        uv_loop = vat.uv_loop
        fs = ruv.alloc_fs()

        path = sibling.asBytes()
        # Use CREAT | EXCL to cause a failure if the temporary file
        # already exists.
        flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL
        sc = SetContents(vat, data, r, sibling, self)
        ruv.stashFS(fs, (vat, sc))
        ruv.fsOpen(uv_loop, fs, path, flags, 0777, openSetContentsCB)
        return p
예제 #17
0
    def open(self, callback, flags=None, mode=None):
        # Always call this as .open(callback, flags=..., mode=...)
        assert flags is not None
        assert mode is not None

        p, r = makePromise()
        vat = currentVat.get()
        uv_loop = vat.uv_loop
        fs = ruv.alloc_fs()

        path = self.asBytes()
        log.log(["fs"],
                u"makeFileResource: Opening file '%s'" % path.decode("utf-8"))
        ruv.stashFS(fs, (vat, r))
        ruv.fsOpen(uv_loop, fs, path, flags, mode, callback)
        return p
예제 #18
0
 def _cleanup(self):
     uv_loop = self._vat.uv_loop
     fs = ruv.alloc_fs()
     ruv.stashFS(fs, (self._vat, self))
     ruv.fsClose(uv_loop, fs, self._fd, ruv.fsUnstashAndDiscard)
     ruv.freeBuf(self._buf)
예제 #19
0
파일: files.py 프로젝트: dckc/typhon
 def append(self, data):
     self.pieces.append(data)
     self.pos += len(data)
     # Queue another!
     ruv.stashFS(self.fs, (self.vat, self))
     self.queueRead()
예제 #20
0
 def append(self, data):
     self.pieces.append(data)
     self.pos += len(data)
     # Queue another!
     ruv.stashFS(self.fs, (self.vat, self))
     self.queueRead()
예제 #21
0
 def _cleanup(self):
     fs = ruv.alloc_fs()
     ruv.stashFS(fs, (self._vat, self))
     ruv.fsClose(self._vat.uv_loop, fs, self._fd, ruv.fsUnstashAndDiscard)
     self.closed = True