Example #1
0
    def truncate(self, path, length, fh=None):
        realpath = self.remotepath(path)
        cachefile = self.cachefile(realpath)
        if not os.path.exists(cachefile):
            if self.empty_file(realpath):
                self.create(path, 'wb')
            else:
                task = Task(
                    xxhash.xxh64(realpath).intdigest(), self.getfile, realpath)
                self.taskpool.submit(task)
                self.taskpool.wait(xxhash.xxh64(realpath).intdigest())

        status = os.truncate(cachefile, length)
        self.logger.info(self.extract(os.lstat(cachefile)))
        self.attributes.insert(realpath, self.extract(os.lstat(cachefile)))
        task = Task(
            xxhash.xxh64(realpath).intdigest(), self._truncate, realpath,
            length)
        self.taskpool.submit(task)
        return status
Example #2
0
    def write(self, path, data, offset, fh):
        realpath = self.remotepath(path)
        cachefile = self.cachefile(realpath)
        if not os.path.exists(cachefile):
            if self.empty_file(realpath):
                self.create(path, 'wb')
            else:
                task = Task(
                    xxhash.xxh64(realpath).intdigest(), self.getfile, realpath)
                self.taskpool.submit(task)
                self.taskpool.wait(xxhash.xxh64(realpath).intdigest())

        with open(cachefile, 'rb+') as outfile:
            outfile.seek(offset, 0)
            outfile.write(data)

        self.attributes.insert(realpath, self.extract(os.lstat(cachefile)))
        task = Task(
            xxhash.xxh64(realpath).intdigest(), self._write, realpath, data,
            offset)
        self.taskpool.submit(task)
        return len(data)
Example #3
0
    def read(self, path, size, offset, fh):
        path = self.remotepath(path)
        cachefile = self.cachefile(path)
        if os.path.exists(cachefile):
            with open(cachefile, 'rb') as infile:
                infile.seek(offset, 0)
                return infile.read(size)

        task = Task(xxhash.xxh64(path).intdigest(), self.getfile, path)
        self.taskpool.submit(task)
        with self.sftp.open(path, 'rb') as infile:
            infile.seek(offset, 0)
            return infile.read(size)
Example #4
0
File: oxfs.py Project: Feiox/oxfs
    def truncate(self, path, length, fh=None):
        path = self.remotepath(path)
        self.logger.info('truncate {}'.format(path))
        cachefile = self.cachefile(path)
        if not os.path.exists(cachefile):
            raise FuseOSError(ENOENT)

        status = os.truncate(cachefile, length)
        self.logger.info(self.extract(os.lstat(cachefile)))
        self.attributes.insert(path, self.extract(os.lstat(cachefile)))
        task = Task(
            xxhash.xxh64(path).intdigest(), self._truncate, path, length)
        self.taskpool.submit(task)
        return status
Example #5
0
File: oxfs.py Project: Feiox/oxfs
    def write(self, path, data, offset, fh):
        path = self.remotepath(path)
        cachefile = self.cachefile(path)
        if not os.path.exists(cachefile):
            raise FuseOSError(ENOENT)

        with open(cachefile, 'rb+') as outfile:
            outfile.seek(offset, 0)
            outfile.write(data)

        self.attributes.insert(path, self.extract(os.lstat(cachefile)))
        task = Task(
            xxhash.xxh64(path).intdigest(), self._write, path, data, offset)
        self.taskpool.submit(task)
        return len(data)
Example #6
0
    def update_attributes(self):
        cache = self.attributes.cache.copy()
        for path, value in cache.items():
            self.logger.info(path)
            attr = ENOENT
            try:
                attr = self.fs.extract(self.sftp.lstat(path))
            except Exception as e:
                self.logger.info(e)

            if value != attr:
                self.attributes.insert(path, attr)
                if not self.can_skip_update(path, value, attr):
                    self.unlink(path)
                    task = Task(
                        xxhash.xxh64(path).intdigest(), self.fs.getfile, path)
                    self.taskpool.submit(task)