Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
 def fsyncdir(self, path, datasync, fh):
     logger.debug("fsyncdir: operation not supported.")
     raise FuseOSError(ENOTSUP)
Ejemplo n.º 5
0
 def mkdir(self, path, mode):
     logger.debug("mkdir: operation not supported.")
     raise FuseOSError(EROFS)
Ejemplo n.º 6
0
 def utimens(self, path, times=None):
     logger.debug("utimens: operation not supported.")
     raise FuseOSError(ENOTSUP)
Ejemplo n.º 7
0
 def rmdir(self, path):
     logger.error("rmdir")
     raise FuseOSError(EROFS)
Ejemplo n.º 8
0
 def symlink(self, target, source):
     logger.error("symlink")
     raise FuseOSError(EROFS)
Ejemplo n.º 9
0
 def truncate(self, path, length, fh=None):
     logger.debug("truncate: operation not supported.")
     raise FuseOSError(EROFS)
Ejemplo n.º 10
0
 def setxattr(self, path, name, value, options, position=0):
     logger.error("setxattr")
     raise FuseOSError(ENOTSUP)
Ejemplo n.º 11
0
 def removexattr(self, path, name):
     logger.debug("removexattr: operation not supported.")
     raise FuseOSError(ENOTSUP)
Ejemplo n.º 12
0
 def write(self, path, data, offset, fh):
     logger.error("write")
     raise FuseOSError(EROFS)
Ejemplo n.º 13
0
    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
Ejemplo n.º 14
0
 def utimens(self, path, times=None):
     logger.error("utimens")
     raise FuseOSError(ENOTSUP)
Ejemplo n.º 15
0
 def unlink(self, path):
     logger.error("unlink")
     raise FuseOSError(EROFS)
Ejemplo n.º 16
0
 def truncate(self, path, length, fh=None):
     logger.error("truncate")
     raise FuseOSError(EROFS)
Ejemplo n.º 17
0
 def mknod(self, path, mode, dev):
     logger.debug("mknod: operation not supported.")
     raise FuseOSError(EROFS)
Ejemplo n.º 18
0
 def rmdir(self, path):
     logger.debug("rmdir: operation not supported.")
     raise FuseOSError(EROFS)
Ejemplo n.º 19
0
 def readlink(self, path):
     logger.debug("readlink: operation not supported.")
     raise FuseOSError(ENOTSUP)
Ejemplo n.º 20
0
 def statfs(self, path):
     logger.debug("statfs: operation not supported.")
     raise FuseOSError(ENOTSUP)
Ejemplo n.º 21
0
 def rename(self, old, new):
     logger.debug("rename: operation not supported.")
     raise FuseOSError(EROFS)
Ejemplo n.º 22
0
 def statfs(self, path):
     logger.error("statfs")
     raise FuseOSError(ENOTSUP)
Ejemplo n.º 23
0
 def setxattr(self, path, name, value, options, position=0):
     logger.debug("setxattr: operation not supported.")
     raise FuseOSError(ENOTSUP)
Ejemplo n.º 24
0
 def chmod(self, path, mode):
     logging.debug("chmod: operation not supported.")
     raise FuseOSError(EROFS)
Ejemplo n.º 25
0
 def symlink(self, target, source):
     logger.debug("symlink: operation not supported.")
     raise FuseOSError(EROFS)
Ejemplo n.º 26
0
 def chown(self, path, uid, gid):
     logger.debug("chown: operation not supported.")
     raise FuseOSError(EROFS)
Ejemplo n.º 27
0
 def unlink(self, path):
     logger.debug("unlink: operation not supported.")
     raise FuseOSError(EROFS)
Ejemplo n.º 28
0
 def create(self, path, mode, fi=None):
     logger.debug("create: operation not supported.")
     raise FuseOSError(EROFS)
Ejemplo n.º 29
0
 def write(self, path, data, offset, fh):
     logger.debug("write: operation not supported.")
     raise FuseOSError(EROFS)
Ejemplo n.º 30
0
 def rename(self, old, new):
     logger.error("rename")
     raise FuseOSError(EROFS)