Skip to content

Commit

Permalink
Merge pull request #558 from jgigault/bug/fix-missing-page-iteration-…
Browse files Browse the repository at this point in the history
…google-json-api

ensure to retrieve all pages when using #files with given block
  • Loading branch information
Temikus authored Jan 15, 2022
2 parents d158969 + 0f19943 commit 8fa62f2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/fog/storage/google_json/models/files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ class Files < Fog::Collection
attribute :page_token, :aliases => %w(pageToken page_token)
attribute :max_results, :aliases => ["MaxKeys", "max-keys"]
attribute :prefix, :aliases => "Prefix"
attribute :next_page_token

def all(options = {})
requires :directory
data = service.list_objects(directory.key, attributes.merge(options))
.to_h[:items] || []
parent = service.list_objects(directory.key, attributes.merge(options))
attributes[:next_page_token] = parent.next_page_token
data = parent.to_h[:items] || []
load(data)
end

Expand All @@ -27,6 +29,10 @@ def each
subset = dup.all

subset.each_file_this_page { |f| yield f }
while subset.next_page_token
subset = subset.all(:page_token => subset.next_page_token)
subset.each_file_this_page { |f| yield f }
end
end
self
end
Expand Down

0 comments on commit 8fa62f2

Please sign in to comment.