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

Fix list_objects and remove_objects methods #198

Merged
merged 4 commits into from
Jan 5, 2023
Merged
Changes from 3 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
14 changes: 8 additions & 6 deletions karton/core/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,10 +625,12 @@ def list_objects(self, bucket: str) -> List[str]:
:param bucket: Bucket name
:return: List of object identifiers
"""
return [
object["Key"]
for object in self.s3.list_objects(Bucket=bucket).get("Contents", [])
]
objs = list()
paginator = self.s3.get_paginator("list_objects_v2")
for page in paginator.paginate(Bucket=bucket):
for obj in page.get("Contents", list()):
objs.append(obj["Key"])
return objs

def remove_object(self, bucket: str, object_uid: str) -> None:
"""
Expand All @@ -646,8 +648,8 @@ def remove_objects(self, bucket: str, object_uids: Iterable[str]) -> None:
:param bucket: Bucket name
:param object_uids: Object identifiers
"""
delete_objects = [{"Key": uid} for uid in object_uids]
self.s3.delete_objects(Bucket=bucket, Delete={"Objects": delete_objects})
for delete_objects in chunks([{"Key": uid} for uid in object_uids], 1000):
self.s3.delete_objects(Bucket=bucket, Delete={"Objects": delete_objects})

def check_bucket_exists(self, bucket: str, create: bool = False) -> bool:
"""
Expand Down