Skip to content

Commit

Permalink
use s3 delete-object to avoid Content-MD5 error
Browse files Browse the repository at this point in the history
  • Loading branch information
FuhuXia committed Sep 18, 2023
1 parent e9ef593 commit c2d18d3
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions ckanext/geodatagov/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,11 @@ def upload_to_key(upload_str: str, filename_on_s3: str) -> None:


def delete_old_sitemaps():
objects_to_delete = S3.list_objects(Bucket=BUCKET_NAME, Prefix=PREFIX)
objects_to_delete = S3.list_objects_v2(Bucket=BUCKET_NAME, Prefix=PREFIX)

delete_keys = {'Objects': []}
delete_keys['Objects'] = [{'Key': k} for k in [obj['Key'] for obj in objects_to_delete.get('Contents', [])]]

S3.delete_objects(Bucket=BUCKET_NAME, Delete=delete_keys)
for object in objects_to_delete['Contents']:
log.info("Deleting {}.".format(object['Key']))
S3.delete_object(Bucket=BUCKET_NAME, Key=object['Key'])


def upload_sitemap_file(sitemap: list) -> None:
Expand Down

0 comments on commit c2d18d3

Please sign in to comment.