Skip to content

Commit

Permalink
Fix googleapis#65 - Added force parameter to delete non empty buckets.
Browse files Browse the repository at this point in the history
  • Loading branch information
kleyow committed Apr 2, 2014
1 parent 4b56a23 commit 95731fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions gcloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def new_key(self, key):

raise TypeError('Invalid key: %s' % key)

def delete(self):
def delete(self, force=False):
"""Delete this bucket.
The bucket **must** be empty in order to delete it.
Expand All @@ -144,7 +144,7 @@ def delete(self):

# TODO: Make sure the proper exceptions are raised.

return self.connection.delete_bucket(self.name)
return self.connection.delete_bucket(self.name, force)

def delete_key(self, key):
# TODO: Should we accept a 'silent' param here to not raise an exception?
Expand Down
7 changes: 6 additions & 1 deletion gcloud/storage/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def create_bucket(self, bucket, *args, **kwargs):
data={'name': bucket.name})
return Bucket.from_dict(response, connection=self)

def delete_bucket(self, bucket, *args, **kwargs):
def delete_bucket(self, bucket, force=False, *args, **kwargs):
"""Delete a bucket.
You can use this method to delete a bucket by name,
Expand Down Expand Up @@ -375,6 +375,11 @@ def delete_bucket(self, bucket, *args, **kwargs):
"""

bucket = self.new_bucket(bucket)

if force:
for key in bucket:
key.delete()

response = self.api_request(method='DELETE', path=bucket.path)
return True

Expand Down

0 comments on commit 95731fe

Please sign in to comment.