def listdir(self, path): """ Return a generator yielding the content of a virtual directory. Behave much like os.listdir() but the result also contains '.' and '..' at the begining. .. note:: raise a 'FuseOSError' exception if the path does not exist or the path is not a directory. Parameters ---------- path: str (mandatory) a virtual path we want to list. """ # Try to get the path informations: get something if the # the path exists path_info = self.content.get(path) # If the path does not exist, raise a 'FuseOSError' exception if path_info is None: raise FuseOSError(ENOENT) # Unpack path information real_path, uid, gid, mode, ctime = path_info # Path is a virtual directory if isinstance(real_path, list): yield "." yield ".." for path in real_path: yield path # Otherwise raise an exception else: raise FuseOSError(ENOTDIR)
def get_real_path(self, path): """ For a file, returns the real path for a given virtual path. .. note:: raise a 'FuseOSError' exception if the path does not exist or the path is not a file. Parameters ---------- path: str (mandatory) a virtual file from which we want to extract his real path. """ # Try to get the file informations: get something if the # the path exists path_info = self.content.get(path) # If the path does not exist, raise a 'FuseOSError' exception if path_info is None: raise FuseOSError(ENOENT) # Unpack path information real_path, uid, gid, mode, ctime = path_info # Path is a virtual file if isinstance(real_path, basestring): return real_path # Otherwise raise an exception else: raise FuseOSError(ENOTDIR)
def open(self, path, flags): """ File-class version of 'open'. Open a file. """ logger.debug("open {0}".format(path)) # Update the log file if requested if self.generate_log: realpath = os.sep.join(path.split(os.sep)[2:]) abspath = os.path.join(self.data_root_dir, realpath) self.log_file.write(" ".join([ str(datetime.datetime.now()), self.instance, self.login, abspath, str(os.path.isfile(abspath)) ])) self.log_file.write("\n") self.log_file.flush() if flags & (os.O_RDWR + os.O_WRONLY): raise FuseOSError(EROFS) # Special case for the rset binary file if os.path.basename(path).startswith("request_result"): return return os.open(self.vdir.get_real_path(path), flags)
def fsyncdir(self, path, datasync, fh): logger.debug("fsyncdir: operation not supported.") raise FuseOSError(ENOTSUP)
def mkdir(self, path, mode): logger.debug("mkdir: operation not supported.") raise FuseOSError(EROFS)
def utimens(self, path, times=None): logger.debug("utimens: operation not supported.") raise FuseOSError(ENOTSUP)
def rmdir(self, path): logger.error("rmdir") raise FuseOSError(EROFS)
def symlink(self, target, source): logger.error("symlink") raise FuseOSError(EROFS)
def truncate(self, path, length, fh=None): logger.debug("truncate: operation not supported.") raise FuseOSError(EROFS)
def setxattr(self, path, name, value, options, position=0): logger.error("setxattr") raise FuseOSError(ENOTSUP)
def removexattr(self, path, name): logger.debug("removexattr: operation not supported.") raise FuseOSError(ENOTSUP)
def write(self, path, data, offset, fh): logger.error("write") raise FuseOSError(EROFS)
def stat(self, path): """ Return a dictionary similar to the result of os.fstat for the given virtual path. .. note:: raise a 'FuseOSError' exception if the path does not exist. Parameters ---------- path: str (mandatory) a virtual path we want to check. """ # Try to get the path informations: get something if the # the path exists path_info = self.content.get(path) # If the path does not exist, raise a 'FuseOSError' exception if path_info is None: raise FuseOSError(ENOENT) # Unpack path information real_path, uid, gid, mode, ctime = path_info # Initilaize the output result = dict(st_uid=uid, st_gid=gid) # Path link to a real file if isinstance(real_path, basestring): # Deal with rset binary file if os.path.basename(path).startswith("request_result"): cwsearch_name = path.split("/")[-2] rset_time = self.content["/" + cwsearch_name][4] result.update({ "st_ctime": rset_time, "st_mtime": rset_time, "st_nlink": 1, "st_mode": 33204, "st_size": self.rset_data[cwsearch_name].len, "st_atime": rset_time }) # File on the file system else: st = os.lstat(real_path) # TODO: Remove write access on st_mode result.update( dict((key, getattr(st, key)) for key in ("st_atime", "st_ctime", "st_mode", "st_mtime", "st_nlink", "st_size"))) # Path is a virtual directory else: result["st_mode"] = stat.S_IFDIR + mode result["st_atime"] = ctime result["st_ctime"] = ctime result["st_mtime"] = ctime # st_nlinks is the number of reference to the directory a: # the number of sub folders in a pointing to a + # a has a referece to itself and the parent directory has # a reference to a. result["st_nlink"] = len(real_path) + 2 result["st_size"] = 4096 return result
def utimens(self, path, times=None): logger.error("utimens") raise FuseOSError(ENOTSUP)
def unlink(self, path): logger.error("unlink") raise FuseOSError(EROFS)
def truncate(self, path, length, fh=None): logger.error("truncate") raise FuseOSError(EROFS)
def mknod(self, path, mode, dev): logger.debug("mknod: operation not supported.") raise FuseOSError(EROFS)
def rmdir(self, path): logger.debug("rmdir: operation not supported.") raise FuseOSError(EROFS)
def readlink(self, path): logger.debug("readlink: operation not supported.") raise FuseOSError(ENOTSUP)
def statfs(self, path): logger.debug("statfs: operation not supported.") raise FuseOSError(ENOTSUP)
def rename(self, old, new): logger.debug("rename: operation not supported.") raise FuseOSError(EROFS)
def statfs(self, path): logger.error("statfs") raise FuseOSError(ENOTSUP)
def setxattr(self, path, name, value, options, position=0): logger.debug("setxattr: operation not supported.") raise FuseOSError(ENOTSUP)
def chmod(self, path, mode): logging.debug("chmod: operation not supported.") raise FuseOSError(EROFS)
def symlink(self, target, source): logger.debug("symlink: operation not supported.") raise FuseOSError(EROFS)
def chown(self, path, uid, gid): logger.debug("chown: operation not supported.") raise FuseOSError(EROFS)
def unlink(self, path): logger.debug("unlink: operation not supported.") raise FuseOSError(EROFS)
def create(self, path, mode, fi=None): logger.debug("create: operation not supported.") raise FuseOSError(EROFS)
def write(self, path, data, offset, fh): logger.debug("write: operation not supported.") raise FuseOSError(EROFS)
def rename(self, old, new): logger.error("rename") raise FuseOSError(EROFS)