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 fetching paginated results with a filter. #4511

Merged
merged 2 commits into from
Dec 17, 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
45 changes: 29 additions & 16 deletions src/clusterfuzz/_internal/google_cloud_utils/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ def list_blobs(self, remote_path, recursive=True, names_only=False):

client = _storage_client()
bucket = client.bucket(bucket_name)
properties = {}

if recursive:
delimiter = None
Expand All @@ -249,23 +248,37 @@ def list_blobs(self, remote_path, recursive=True, names_only=False):
else:
fields = None

iterator = bucket.list_blobs(
prefix=path, delimiter=delimiter, fields=fields)
for blob in iterator:
properties['bucket'] = bucket_name
properties['name'] = blob.name
properties['updated'] = blob.updated
properties['size'] = blob.size

yield properties

if not recursive:
# When doing delimiter listings, the "directories" will be in `prefixes`.
for prefix in iterator.prefixes:
properties['bucket'] = bucket_name
properties['name'] = prefix
iterations = 0
while True:
jonathanmetzman marked this conversation as resolved.
Show resolved Hide resolved
iterations += 1
iterator = bucket.list_blobs(
prefix=path, delimiter=delimiter, fields=fields)
for blob in iterator:
properties = {
'bucket': bucket_name,
'name': blob.name,
'updated': blob.updated,
'size': blob.size,
}

yield properties

if not recursive:
# When doing delimiter listings, the "directories" will be in
# `prefixes`.
for prefix in iterator.prefixes:
properties = {
'bucket': bucket_name,
'name': prefix,
}
yield properties

next_page_token = iterator.next_page_token
if next_page_token is None:
break
if iterations and iterations % 50 == 0:
logs.error('Might be infinite looping.')
jonathanmetzman marked this conversation as resolved.
Show resolved Hide resolved

def copy_file_from(self, remote_path, local_path):
"""Copy file from a remote path to a local path."""
client = _storage_client()
Expand Down
Loading