示例#1
0
    def create(self, path, mode):
        if RootlevelResolver.is_rootlevel_path(path):
            raise OSError(errno.EROFS)  #read only

        process_context, path_suffix = self.resolve_proc_path(path)
        mock_context.run_as(process_context, elektra_fuse_interface.create,
                            path_suffix, mode)
        return self._new_fd()
示例#2
0
 def chmod(self, path, mode):
     if RootlevelResolver.is_rootlevel_path(path):
         raise OSError(errno.EROFS)
     process_context, path_suffix = self.resolve_proc_path(path)
     return mock_context.run_as(process_context,
                                elektra_fuse_interface.chmod, path_suffix,
                                mode)
示例#3
0
    def readdir(self, path, fh):

        if path == "/":
            all_pids = self._get_all_pids()

            #filter out processes with working directory under mount point to prevent endless recursions (e.g. an interactive shell navigating below the mount point)
            #excluded_pids = {pid for pid in all_pids if self._is_path_child_of(mock_context.parse_process_context_of_pid(pid).cwd, self.mountpoint)}

            excluded_pids = set()
            for pid in all_pids:
                try:
                    pid_cwd_resolved = os.readlink("/proc/%s/cwd" % pid)
                except OSError:
                    #process does not exist any more
                    excluded_pids.add(pid)
                if self._is_path_child_of(pid_cwd_resolved, self.mountpoint):
                    excluded_pids.add(pid)

            displayed_pids = all_pids - excluded_pids

            return ['.', '..', *displayed_pids]

        process_context, path_suffix = self.resolve_proc_path(path)

        return mock_context.run_as(process_context,
                                   elektra_fuse_interface.readdir, path_suffix,
                                   fh)
示例#4
0
    def removexattr(self, path, name):
        if RootlevelResolver.is_rootlevel_path(path):
            raise OSError(errno.EROFS)  #read only fs

        process_context, path_suffix = self.resolve_proc_path(path)
        return mock_context.run_as(process_context,
                                   elektra_fuse_interface.removexattr,
                                   path_suffix, name)
示例#5
0
 def write(self, path, data, offset, fh):
     if RootlevelResolver.is_rootlevel_path(path):
         if _exists_in_rootlevel(path):
             raise OSError(errno.EROFS)  #read-only fs
         else:
             raise OSError(errno.ENOENT)  #does not exist
     process_context, path_suffix = self.resolve_proc_path(path)
     return mock_context.run_as(process_context,
                                elektra_fuse_interface.write, path_suffix,
                                data, offset, fh)
示例#6
0
    def read(self, path, size, offset, fh):
        if RootlevelResolver.is_rootlevel_path(path):
            if _exists_in_rootlevel(path):
                raise OSError(errno.EISDIR)  #is dir
            else:
                raise OSError(errno.ENOENT)  #does not exist

        process_context, path_suffix = self.resolve_proc_path(path)
        return mock_context.run_as(process_context,
                                   elektra_fuse_interface.read, path_suffix,
                                   size, offset, fh)
示例#7
0
    def setxattr(self, path, name, value, options, position=0):
        if RootlevelResolver.is_rootlevel_path(path):
            raise OSError(errno.EROFS)

        process_context, path_suffix = self.resolve_proc_path(path)
        return mock_context.run_as(process_context,
                                   elektra_fuse_interface.setxattr,
                                   path_suffix,
                                   name,
                                   value,
                                   options,
                                   position=position)
示例#8
0
    def truncate(self, path, length, fh=None):
        if RootlevelResolver.is_rootlevel_path(path):
            if _exists_in_rootlevel(path):
                raise OSError(errno.EROFS)
            else:
                raise OSError(errno.ENOENT)

        process_context, path_suffix = self.resolve_proc_path(path)
        return mock_context.run_as(process_context,
                                   elektra_fuse_interface.truncate,
                                   path_suffix,
                                   length,
                                   fh=fh)
示例#9
0
    def rename(self, old_path, new_path):
        if RootlevelResolver.is_rootlevel_path(
                old_path) or RootlevelResolver.is_rootlevel_path(new_path):
            raise OSError(errno.EROFS)

        process_context_old_path, old_path_suffix = self.resolve_proc_path(
            old_path)
        process_context_new_path, new_path_suffix = self.resolve_proc_path(
            new_path)

        if process_context_old_path.pid != process_context_new_path.pid:
            raise OSError(errno.EINVAL)
        return mock_context.run_as(process_context_old_path,
                                   elektra_fuse_interface.rename,
                                   old_path_suffix, new_path_suffix)
示例#10
0
    def getattr(self, path, fh=None):
        generic_dir_attrs = dict(st_mode=(stat.S_IFDIR | 0o0444),
                                 st_ctime=elektra_fuse_interface.startup_time,
                                 st_mtime=elektra_fuse_interface.startup_time,
                                 st_atime=elektra_fuse_interface.startup_time,
                                 st_nlink=2)

        if RootlevelResolver.is_rootlevel_path(path):
            if self._exists_in_rootlevel(path):
                return generic_dir_attrs
            else:
                raise OSError(errno.ENOENT)

        process_context, path_suffix = self.resolve_proc_path(path)

        return mock_context.run_as(process_context,
                                   elektra_fuse_interface.getattr,
                                   path_suffix,
                                   fh=fh)
示例#11
0
    def listxattr(self, path):

        if RootlevelResolver.is_rootlevel_path(path):
            if path == "/":
                return []
            elif self._exists_in_rootlevel(path):
                pid = int(Path(path).name)
                process_context = mock_context.parse_process_context_of_pid(
                    pid)
                return process_context._fields
            else:
                raise OSError(errno.ENOENT)

            return

        process_context, path_suffix = self.resolve_proc_path(path)
        return mock_context.run_as(process_context,
                                   elektra_fuse_interface.listxattr,
                                   path_suffix)
示例#12
0
    def getxattr(self, path, name, position=0):
        if RootlevelResolver.is_rootlevel_path(path):
            if path == "/":
                raise OSError(errno.ENOENT)
            elif self._exists_in_rootlevel(path):
                pid = int(Path(path).name)
                process_context_dict = mock_context.parse_process_context_of_pid(
                    pid)._asdict()

                if name in process_context_dict:
                    return str(process_context_dict[name]).encode()
                else:
                    raise OSError(errno.ENOENT)

            else:
                raise OSError(errno.ENOENT)

        process_context, path_suffix = self.resolve_proc_path(path)
        return mock_context.run_as(process_context,
                                   elektra_fuse_interface.getxattr,
                                   path_suffix,
                                   name,
                                   position=position)