Пример #1
0
    def removedir(self, path):
        self.check()
        _path = self.validatepath(path)

        if _path == "/":
            raise errors.RemoveRootError()

        info = self.getinfo(_path)

        if not info.is_dir:
            raise errors.DirectoryExpected(path)

        if not self.isempty(path):
            raise errors.DirectoryNotEmpty(path)

        _key = self._path_to_dir_key(_path)
        self.client.delete_object(Bucket=self._bucket_name, Key=_key)
Пример #2
0
    def removedir(self, path):
        _path = self.fix_path(path)

        if _path == "/":
            raise errors.RemoveRootError()

        try:
            info = self.getinfo(path)
            if not info.is_dir:
                raise errors.DirectoryExpected(path=path)
            if len(self.listdir(path)) > 0:
                raise errors.DirectoryNotEmpty(path=path)
            self.dropbox.files_delete_v2(_path)
        except ApiError as e:
            if isinstance(e.error._value, LookupError):
                raise errors.ResourceNotFound(path=path)

            raise errors.FileExpected(path=path, exc=e)
Пример #3
0
    def removedir(self, path):
        """
        Remove directory under `path`.

        The directory must be empty.

        :param str path: Path pointing to a directory.
        """
        # type: (Text) -> None

        path = ensureUnicode(path)
        self.check()
        _path = toAscii(self.validatepath(path))
        if _path == "/":
            raise errors.RemoveRootError()
        info = self.getinfo(path)
        if not info.is_dir:
            raise errors.DirectoryExpected(path)
        if not self.isempty(path):
            raise errors.DirectoryNotEmpty(path)

        self._odfs.unlink(_path)
    def removedir(self, path):
        # type: (Text) -> None
        """Remove a directory from the filesystem.

        Arguments:
            path (str): Path of the directory to remove.

        Raises:
            fs.errors.DirectoryNotEmpty: If the directory is not empty (
                see `~fs.base.FS.removetree` for a way to remove the
                directory contents.).
            fs.errors.DirectoryExpected: If the path does not refer to
                a directory.
            fs.errors.ResourceNotFound: If no resource exists at the
                given path.
            fs.errors.RemoveRootError: If an attempt is made to remove
                the root directory (i.e. ``'/'``)

        """
        _path = self.validatepath(path)
        if _path == "/" or _path == "" or _path is None:
            raise errors.RemoveRootError()
        if _path.endswith("/"):
            _path = _path[:-1]

        with self._lock:
            _res = self._getresource(path)
            if not _res:
                raise errors.ResourceNotFound(path)

            if not _res.is_collection:
                raise errors.DirectoryExpected(path)

            if len(_res.get_member_names()) > 0:
                raise errors.DirectoryNotEmpty(path)

            # _res.delete(recursive=False)
            _res.delete()