Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue cinegodcp#1247 : refacto remove objects to return not_found if … #2

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions cn_s3_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,18 @@ def remove(self, bucket_name, prefix):
def remove_objects(self, bucket_name, prefixes):

bucket = self._s3_resource.Bucket(bucket_name)
delete_responses = {}
objects_list = []
for prefix in prefixes:
objects_to_delete = bucket.objects.filter(Prefix=prefix)
objects_list.extend([{'Key': obj.key} for obj in objects_to_delete])

if objects_list:
try:
response = bucket.delete_objects(Delete={'Objects': objects_list})
delete_responses = response
except Exception as e:
self._logger.error(f"Exception occurred while deleting objects: {e}")

return delete_responses
if not objects_list:
return {'not_found': True}
try:
return bucket.delete_objects(Delete={'Objects': objects_list})
except Exception as e:
self._logger.error(f"Exception occurred while deleting objects: {e}")
raise e

def remove_bucket(self, bucket_name, _id):
bucket = self._s3_resource.Bucket(bucket_name)
Expand Down