Exemplo n.º 1
0
    def remove(self, path, recursive=True):
        (bucket, obj) = self._path_to_bucket_and_key(path)

        if self._is_root(obj):
            raise InvalidDeleteException(
                "Cannot delete root of bucket at path {}".format(path))

        if self._obj_exists(bucket, obj):
            self.client.objects().delete(bucket=bucket, object=obj).execute()
            _wait_for_consistency(lambda: not self._obj_exists(bucket, obj))
            return True

        if self.isdir(path):
            if not recursive:
                raise InvalidDeleteException(
                    "Path {} is a directory. Must use recursive delete".format(
                        path))

            req = http.BatchHttpRequest()
            for it in self._list_iter(bucket, self._add_path_delimiter(obj)):
                req.add(self.client.objects().delete(bucket=bucket,
                                                     object=it["name"]))
            req.execute()

            _wait_for_consistency(lambda: not self.isdir(path))
            return True

        return False
Exemplo n.º 2
0
    def remove(self, path, recursive=True, skip_trash=True):
        (
            storage_account,
            container_name,
            prefix,
        ) = self._path_to_account_container_and_blob(path)
        assert self.account == storage_account

        if self._is_container(prefix):
            self.conn.delete_container(container_name)
            _wait_for_consistency(lambda: not self.isdir(path))
            return

        if self.isdir(path):
            if not recursive:
                raise InvalidDeleteException(
                    "Path {} is a directory. Must use recursive delete".format(
                        path))

            blobs = self.listdir(path)
            for b in blobs:
                _, _, blob_to_remove = self._path_to_account_container_and_blob(
                    b)
                self.conn.delete_blob(container_name, blob_to_remove)
            _wait_for_consistency(lambda: not self.isdir(path))
            return

        self.conn.delete_blob(container_name, prefix)
        _wait_for_consistency(lambda: not self.exists(path))
        return