def flush(self, fh): if not fh.dirty: return fh.flush_ret try: json = fh.buffer.getvalue() if len(json.strip()): doc = loads(json.decode(self.mongofs.json_encoding, errors="replace")) else: doc = {} except ValueError, e: notify("Invalid MongoFS document", "\n".join(str(e).split(":"))) fh.dirty = False fh.flush_ret = -errno.EIO return fh.flush_ret
def getattr(self): # If the file is already open, return the size of the buffer if self.mongofs.fetch_file_length: fh = self.open(0) else: fh = self.mongofs.open_file_cache.get(self.id, None) if isinstance(fh, MongoSharedFileHandle): if self.mongofs.fetch_file_length: self.release(0, fh) return fuse.Stat(st_mode=stat.S_IFREG | 0666, st_nlink=1, st_size=len(fh.buffer.getvalue())) # It is faster to check the cached response of readdir() instead of looking up Mongo parent_field = self.id[-2] parent_filter = dict(self.filter) del parent_filter[parent_field] for valid_file in MongoFilter( self.mongofs, self.database, self.collection, parent_filter, parent_field ).list_files(): if valid_file.endswith(".json"): valid_file = valid_file[:-5] if self.id[-1] == loads(valid_file): return fuse.Stat(st_mode=stat.S_IFREG | 0666, st_nlink=1, st_size=1) return -errno.ENOENT