From: Daira Hopwood Date: Tue, 18 Mar 2014 01:03:24 +0000 (+0000) Subject: S3 container: treat an empty GET bucket response as an error. X-Git-Url: https://git.rkrishnan.org/pf/content/simplejson/install.html?a=commitdiff_plain;h=07978191b11c3d7b7d8d56fdd693865c9ce8d4cc;p=tahoe-lafs%2Ftahoe-lafs.git S3 container: treat an empty GET bucket response as an error. Signed-off-by: Daira Hopwood --- diff --git a/src/allmydata/storage/backends/cloud/s3/s3_container.py b/src/allmydata/storage/backends/cloud/s3/s3_container.py index 84b9edb9..806ae611 100644 --- a/src/allmydata/storage/backends/cloud/s3/s3_container.py +++ b/src/allmydata/storage/backends/cloud/s3/s3_container.py @@ -1,6 +1,11 @@ from zope.interface import implements +try: + from xml.etree.ElementTree import ParseError +except ImportError: + from elementtree.ElementTree import ParseError + from allmydata.node import InvalidValueError from allmydata.storage.backends.cloud.cloud_common import IContainer, \ ContainerRetryMixin, ContainerListMixin @@ -65,8 +70,16 @@ class S3Container(ContainerRetryMixin, ContainerListMixin): def delete(self): return self._do_request('delete bucket', self.client.delete_bucket, self.container_name) + def _get_bucket(self, container_name, **kwargs): + d = self.client.get_bucket(container_name, **kwargs) + def _err(f): + f.trap(ParseError) + raise self.ServiceError("", 500, "list objects: response body is not valid XML (possibly empty)\n" + f) + d.addErrback(_err) + return d + def list_some_objects(self, **kwargs): - return self._do_request('list objects', self.client.get_bucket, self.container_name, **kwargs) + return self._do_request('list objects', self._get_bucket, self.container_name, **kwargs) def put_object(self, object_name, data, content_type='application/octet-stream', metadata={}): return self._do_request('PUT object', self.client.put_object, self.container_name,