Python fuse.FuseOSError() Examples

The following are 30 code examples of fuse.FuseOSError(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module fuse , or try the search function .
Example #1
Source File: mount.py    From python-ntfs with Apache License 2.0 6 votes vote down vote up
def _get_path_entry(self, path):
        root = self._fs.get_root_directory()
        if path == "/":
            g_logger.debug("asking for root")
            entry = root
        else:
            _, __, rest = path.partition("/")
            g_logger.debug("asking for: %s", rest)
            try:
                entry = root.get_path_entry(rest)
            except ChildNotFoundError:
                raise FuseOSError(errno.ENOENT)
        return entry

    # Filesystem methods
    # ================== 
Example #2
Source File: baidufuse2.py    From baidu-fuse with GNU General Public License v2.0 6 votes vote down vote up
def getattr(self, path, fh=None):
        #print 'getattr *',path
        # 先看缓存中是否存在该文件

        if not self.buffer.has_key(path):
            print path,'未命中'
            #print self.buffer
            #print self.traversed_folder
            jdata = json.loads(self.disk.meta([path]).content)
            try:
                if 'info' not in jdata:
                    raise FuseOSError(errno.ENOENT)
                if jdata['errno'] != 0:
                    raise FuseOSError(errno.ENOENT)
                file_info = jdata['info'][0]
                self._add_file_to_buffer(path,file_info)
                st = self.buffer[path].getDict()
                return st
            except:
                raise FuseOSError(errno.ENOENT)
        else:
            #print path,'命中'
            return self.buffer[path].getDict() 
Example #3
Source File: not_in.py    From gitfs with Apache License 2.0 6 votes vote down vote up
def check_args(self, f, methods_args):
        to_check = []

        args = inspect.getargspec(f)
        for arg in self.check:
            if arg in args[0]:
                to_check.append(args[0].index(arg))

        for index in to_check:
            arg = methods_args[index - 1]

            if self.look_at.cache.get(arg, False):
                raise FuseOSError(errno.EACCES)

            if self.look_at.check_key(arg):
                self.look_at.cache[arg] = True
                raise FuseOSError(errno.ENOENT)

            self.look_at.cache[arg] = False 
Example #4
Source File: write_operation.py    From gitfs with Apache License 2.0 6 votes vote down vote up
def write_operation(f):
    @wraps(f)
    def decorated(*args, **kwargs):
        if not fetch_successful.is_set() or not push_successful.is_set():
            raise FuseOSError(EROFS)

        global writers
        writers += 1

        if syncing.is_set():
            log.debug("WriteOperation: Wait until syncing is done")
            sync_done.wait()

        try:
            result = f(*args, **kwargs)
        finally:
            writers -= 1

        return result

    return decorated 
Example #5
Source File: index.py    From gitfs with Apache License 2.0 6 votes vote down vote up
def getattr(self, path, fh=None):
        """
        Returns a dictionary with keys identical to the stat C structure of
        stat(2).

        st_atime, st_mtime and st_ctime should be floats.

        NOTE: There is an incombatibility between Linux and Mac OS X
        concerning st_nlink of directories. Mac OS X counts all files inside
        the directory, while Linux counts only the subdirectories.
        """

        if path != "/":
            raise FuseOSError(ENOENT)

        attrs = super(IndexView, self).getattr(path, fh)
        attrs.update({"st_mode": S_IFDIR | 0o555, "st_nlink": 2})

        return attrs 
Example #6
Source File: current.py    From gitfs with Apache License 2.0 6 votes vote down vote up
def chmod(self, path, mode):
        """
        Executes chmod on the file at os level and then it commits the change.
        """
        str_mode = ("%o" % mode)[-4:]
        if str_mode not in ["0755", "0644"]:
            raise FuseOSError(errno.EINVAL)

        result = super(CurrentView, self).chmod(path, mode)

        if os.path.isdir(self.repo._full_path(path)):
            return result

        message = "Chmod to {} on {}".format(str_mode, path)
        self._stage(add=path, message=message)

        log.debug("CurrentView: Change %s mode to %s", path, ("0%o" % mode)[-4:])
        return result 
Example #7
Source File: fuse_operations.py    From parsec-cloud with GNU Affero General Public License v3.0 6 votes vote down vote up
def translate_error(event_bus, operation, path):
    try:
        yield

    except FuseOSError:
        raise

    except FSLocalOperationError as exc:
        raise FuseOSError(exc.errno) from exc

    except FSRemoteOperationError as exc:
        event_bus.send(CoreEvent.MOUNTPOINT_REMOTE_ERROR, exc=exc, operation=operation, path=path)
        raise FuseOSError(exc.errno) from exc

    except Exception as exc:
        logger.exception("Unhandled exception in fuse mountpoint")
        event_bus.send(
            CoreEvent.MOUNTPOINT_UNHANDLED_ERROR, exc=exc, operation=operation, path=path
        )
        # Use EINVAL as fallback error code, since this is what fusepy does.
        raise FuseOSError(errno.EINVAL) from exc 
Example #8
Source File: test_commit.py    From gitfs with Apache License 2.0 6 votes vote down vote up
def test_access_with_invalid_path(self):
        mocked_repo = MagicMock()
        mocked_validation = MagicMock()
        mocked_commit = MagicMock()

        mocked_commit.tree = "tree"
        mocked_repo.revparse_single.return_value = mocked_commit
        mocked_validation.return_value = False

        with patch("gitfs.views.commit.split_path_into_components") as split:
            split.return_value = "elements"

            view = CommitView(repo=mocked_repo, commit_sha1="sha1")
            view._validate_commit_path = mocked_validation
            view.relative_path = "relative_path"

            with pytest.raises(FuseOSError):
                view.access("path", "mode")

            split.assert_called_once_with("relative_path")
            mocked_validation.assert_called_once_with("tree", "elements") 
Example #9
Source File: baidufuse.py    From baidu-fuse with GNU General Public License v2.0 6 votes vote down vote up
def getattr(self, path, fh=None):
        #print 'getattr *',path
        # 先看缓存中是否存在该文件

        if not self.buffer.has_key(path):
            print path,'未命中'
            #print self.buffer
            #print self.traversed_folder
            jdata = json.loads(self.disk.meta([path]).content)
            try:
                if 'info' not in jdata:
                    raise FuseOSError(errno.ENOENT)
                if jdata['errno'] != 0:
                    raise FuseOSError(errno.ENOENT)
                file_info = jdata['info'][0]
                self._add_file_to_buffer(path,file_info)
                st = self.buffer[path].getDict()
                return st
            except:
                raise FuseOSError(errno.ENOENT)
        else:
            #print path,'命中'
            return self.buffer[path].getDict() 
Example #10
Source File: oxfs.py    From oxfs with MIT License 6 votes vote down vote up
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:
                raise FuseOSError(ENOENT)

        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 #11
Source File: oxfs.py    From oxfs with MIT License 6 votes vote down vote up
def getattr(self, path, fh=None):
        path = self.remotepath(path)
        attr = self.attributes.fetch(path)
        if attr is not None:
            if ENOENT == attr:
                raise FuseOSError(ENOENT)
            return attr

        self.logger.info('sftp getattr {}'.format(path))
        try:
            attr = self.extract(self.sftp.lstat(path))
            self.attributes.insert(path, attr)
            return attr
        except:
            self.attributes.insert(path, ENOENT)
            raise FuseOSError(ENOENT) 
Example #12
Source File: fuse.py    From filesystem_spec with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def getattr(self, path, fh=None):
        path = "".join([self.root, path.lstrip("/")]).rstrip("/")
        try:
            info = self.fs.info(path)
        except FileNotFoundError:
            raise FuseOSError(ENOENT)
        data = {"st_uid": 1000, "st_gid": 1000}
        perm = 0o777

        if info["type"] != "file":
            data["st_mode"] = stat.S_IFDIR | perm
            data["st_size"] = 0
            data["st_blksize"] = 0
        else:
            data["st_mode"] = stat.S_IFREG | perm
            data["st_size"] = info["size"]
            data["st_blksize"] = 5 * 2 ** 20
            data["st_nlink"] = 1
        data["st_atime"] = time.time()
        data["st_ctime"] = time.time()
        data["st_mtime"] = time.time()
        return data 
Example #13
Source File: test_passthrough.py    From gitfs with Apache License 2.0 6 votes vote down vote up
def test_access(self):
        mocked_access = MagicMock()
        mocked_access.side_effect = [True, True, False]

        with patch("gitfs.views.passthrough.os.access", mocked_access):
            view = PassthroughView(repo=self.repo, repo_path=self.repo_path)

            # normal, easy test
            view.access("good/relative/path", 777)
            # test if _full_path works
            view.access("/good/relative/path", 777)
            # test if proper exception is raised
            with raises(FuseOSError):
                view.access("/relative/path", 777)

            asserted_calls = [
                call("/the/root/path/good/relative/path", 777),
                call("/the/root/path/good/relative/path", 777),
                call("/the/root/path/relative/path", 777),
            ]
            mocked_access.assert_has_calls(asserted_calls)
            assert mocked_access.call_count == 3 
Example #14
Source File: filesystem.py    From kubefuse with Apache License 2.0 6 votes vote down vote up
def list_files(self, path):
        p = KubePath().parse_path(path)
        if not p.exists(self.client):
            logger.info("path doesn't exist")
            raise FuseOSError(errno.ENOENT)
        if not p.is_dir():
            logger.info("not a directory")
            raise FuseOSError(errno.ENOTDIR)
        if p.object_id is not None: 
            if p.resource_type != 'pod':
                return p.SUPPORTED_ACTIONS
            else:
                return p.SUPPORTED_POD_ACTIONS
        if p.resource_type is not None:
            return self.client.get_entities(p.namespace, p.resource_type)
        if p.namespace is not None:
            return p.SUPPORTED_RESOURCE_TYPES
        return self.client.get_namespaces()  # + ['all'] 
Example #15
Source File: passthrough.py    From python-fuse-sample with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def access(self, path, mode):
        full_path = self._full_path(path)
        if not os.access(full_path, mode):
            raise FuseOSError(errno.EACCES) 
Example #16
Source File: fuse_operations.py    From parsec-cloud with GNU Affero General Public License v3.0 5 votes vote down vote up
def create(self, path: FsPath, mode: int):
        if is_banned(path.name):
            raise FuseOSError(errno.EACCES)
        _, fd = self.fs_access.file_create(path, open=True)
        return fd 
Example #17
Source File: ytfs.py    From ytfs with MIT License 5 votes vote down vote up
def rename(self, old, new):

        """
        Directory renaming support. Needed because many file managers create directories with default names, wich
        makes it impossible to perform a search without CLI. Name changes for files are not allowed, only for
        directories.

        Parameters
        ----------
        old : str
            Old name. Converted to tuple identifier by ``_pathdec`` decorator.
        new : str
            New name. Converted to tuple identifier in actual function body.
        """

        new = self.__pathToTuple(new)

        if not self.__exists(old):
            raise FuseOSError(errno.ENOENT)

        if self.PathType.get(old) is not self.PathType.subdir or self.PathType.get(new) is not self.PathType.subdir:
            raise FuseOSError(errno.EPERM)

        if self.__exists(new):
            raise FuseOSError(errno.EEXIST)

        try:
            new_dir_ent = YTActions(new[0])
            new_dir_ent.updateResults()
        except ConnectionError:
            raise FuseOSError(errno.ENETDOWN)

        self.searches[new[0]] = new_dir_ent # as in mkdir

        try:
            del self.searches[old[0]]

        except KeyError:
            raise FuseOSError(errno.ENOENT)

        return 0 
Example #18
Source File: fuse_operations.py    From parsec-cloud with GNU Affero General Public License v3.0 5 votes vote down vote up
def readdir(self, path: FsPath, fh: int):
        stat = self.fs_access.entry_info(path)

        if stat["type"] == "file":
            raise FuseOSError(errno.ENOTDIR)

        return [".", ".."] + list(stat["children"]) 
Example #19
Source File: ytfs.py    From ytfs with MIT License 5 votes vote down vote up
def write(self, tid, data, offset, fh):

        """
        Write operation. Applicable only for control files - updateResults is called.

        Parameters
        ----------
        tid : str
            Path to file. Original `path` argument is converted to tuple identifier by ``_pathdec`` decorator.
        data : bytes
            Ignored.
        offset : int
            Ignored.
        fh : int
            File descriptor.

        Returns
        -------
        int
            Length of data written.
        """

        if tid[1] == " next":
            d = True
        elif tid[1] == " prev":
            d = False
        else:
            raise FuseOSError(errno.EPERM)

        try:
            self.searches[tid[0]].updateResults(d)
        except KeyError:
            raise FuseOSError(errno.EINVAL) # sth went wrong...
        except ConnectionError:
            raise FuseOSError(errno.ENETDOWN)

        return len(data) 
Example #20
Source File: ytfs.py    From ytfs with MIT License 5 votes vote down vote up
def read(self, tid, length, offset, fh):

        """
        Read from a file. Data is obtained from ``YTStor`` object (which is kept under `fh` descriptor) using its
        ``read`` method.

        Parameters
        ----------
        tid : str
            Path to file. Original `path` argument is converted to tuple identifier by ``_pathdec`` decorator.
        length : int
            Length of data to read.
        offset : int
            Posision from which reading will start.
        fh : int
            File descriptor.

        Returns
        -------
        bytes
            Movie data.
        """

        try:
            return self.fds[fh].read(offset, length, fh)

        except AttributeError: # control file

            if tid[1] not in (" next", " prev"):
                raise FuseOSError(errno.EINVAL)

            return self.__sh_script[offset:offset+length]

        except KeyError: # descriptor does not exist.
            raise FuseOSError(errno.EBADF)

        except ConnectionError:
            raise FuseOSError(errno.ESTALE) 
Example #21
Source File: ytfs.py    From ytfs with MIT License 5 votes vote down vote up
def release(self, tid, fh):

        """
        Close file. Descriptor is removed from ``self.fds``.

        Parameters
        ----------
        tid : str
            Path to file. Ignored.
        fh : int
            File descriptor to release.
        """

        try:
            try:
                self.fds[fh].unregisterHandler(fh)

            except AttributeError:
                pass

            del self.fds[fh]

        except KeyError:
            raise FuseOSError(errno.EBADF)

        return 0 
Example #22
Source File: baidufuse.py    From baidu-fuse with GNU General Public License v2.0 5 votes vote down vote up
def open(self, path, flags):
        self.readLock.acquire()
        print '*'*10,'OPEN CALLED',path,flags
        #print '[****]',path
        """
        Permission denied

        accmode = os.O_RDONLY | os.O_WRONLY | os.O_RDWR
        if (flags & accmode) != os.O_RDONLY:
            raise FuseOSError(errno.EACCES)
        """
        self.fd += 1
        self.readLock.release()
        
        return self.fd 
Example #23
Source File: test_not_in.py    From gitfs with Apache License 2.0 5 votes vote down vote up
def test_has_key(self):
        mocked_inspect = MagicMock()
        mocked_inspect.getargspec.return_value = [["file"]]
        mocked_gitignore = MagicMock()
        mocked_gitignore.get.return_value = False
        mocked_look_at = MagicMock()
        mocked_look_at.cache = mocked_gitignore
        mocked_look_at.check_key.return_value = True

        with patch.multiple("gitfs.utils.decorators.not_in", inspect=mocked_inspect):
            with pytest.raises(FuseOSError):
                not_in(mocked_look_at, check=["file"]).check_args(None, "file") 
Example #24
Source File: test_not_in.py    From gitfs with Apache License 2.0 5 votes vote down vote up
def test_in_cache(self):
        mocked_inspect = MagicMock()
        mocked_inspect.getargspec.return_value = [["file"]]
        mocked_gitignore = MagicMock()
        mocked_gitignore.get.return_value = True
        mocked_look_at = MagicMock()
        mocked_look_at.cache = mocked_gitignore

        with patch.multiple("gitfs.utils.decorators.not_in", inspect=mocked_inspect):
            with pytest.raises(FuseOSError):
                not_in(mocked_look_at, check=["file"]).check_args(None, "file") 
Example #25
Source File: test_history.py    From gitfs with Apache License 2.0 5 votes vote down vote up
def test_access_with_date_and_invalid_path(self):
        mocked_repo = MagicMock()
        mocked_repo.get_commits_by_date.return_value = ["tomorrow"]

        history = HistoryView(repo=mocked_repo)
        history.date = "now"

        with pytest.raises(FuseOSError):
            history.access("/non", "mode")

        mocked_repo.get_commits_by_date.assert_called_once_with("now") 
Example #26
Source File: test_history.py    From gitfs with Apache License 2.0 5 votes vote down vote up
def test_access_with_invalid_path_and_no_date(self):
        history = HistoryView()

        with pytest.raises(FuseOSError):
            history.access("path", "mode") 
Example #27
Source File: test_history.py    From gitfs with Apache License 2.0 5 votes vote down vote up
def test_getattr_with_incorrect_path(self):
        mocked_repo = MagicMock()

        mocked_repo.get_commit_dates.return_value = ["/path"]

        with patch("gitfs.views.history.lru_cache") as mocked_cache:
            mocked_cache.__call__ = lambda f: f

            history = HistoryView(repo=mocked_repo, uid=1, gid=1, mount_time="now")

            with pytest.raises(FuseOSError):
                history.getattr("/not-ok", 1) 
Example #28
Source File: test_index.py    From gitfs with Apache License 2.0 5 votes vote down vote up
def test_getattr_with_non_root_path(self):
        view = IndexView()

        with pytest.raises(FuseOSError):
            view.getattr("/path") 
Example #29
Source File: test_read_only.py    From gitfs with Apache License 2.0 5 votes vote down vote up
def test_access(self):
        view = ReadOnlyView()

        with pytest.raises(FuseOSError):
            view.access("path", os.W_OK)
        assert view.access("path", os.R_OK) == 0 
Example #30
Source File: test_read_only.py    From gitfs with Apache License 2.0 5 votes vote down vote up
def test_cant_write(self):
        view = ReadOnlyView()

        for method in ["write", "create", "utimens", "chmod", "mkdir"]:
            with pytest.raises(FuseOSError):
                getattr(view, method)("path", 1)

        with pytest.raises(FuseOSError):
            view.getxattr("path", "name", 1)

        with pytest.raises(FuseOSError):
            view.chown("path", 1, 1)