Skip to content

Commit

Permalink
Merge pull request #237 from linode/feature/bucket-recursive-delete
Browse files Browse the repository at this point in the history
Allow recursively deleting not-empty buckets
  • Loading branch information
Dorthu authored May 17, 2021
2 parents 527fcf9 + 0484464 commit b212eef
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions linodecli/plugins/obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,25 @@ def delete_bucket(get_client, args):

parser.add_argument('name', metavar='NAME', type=str,
help="The name of the bucket to remove.")
parser.add_argument('--recursive', action="store_true",
help="If given, force removal of non-empty buckets by deleting "
"all objects in the bucket before deleting the bucket. For "
"large buckets, this may take a while.")

parsed = parser.parse_args(args)
client = get_client()

if parsed.recursive:
try:
bucket = client.get_bucket(parsed.name)
except S3ResponseError:
print('No bucket named '+parsed.name)
sys.exit(2)

for c in bucket.list():
print("delete: {} {}".format(parsed.name, c.key))
bucket.delete_key(c)

client.delete_bucket(parsed.name)

print("Bucket {} removed".format(parsed.name))
Expand Down

0 comments on commit b212eef

Please sign in to comment.