Skip to content

Commit

Permalink
support listing of buckets with more than 1000 objects
Browse files Browse the repository at this point in the history
  • Loading branch information
elia authored and Jakub Kuźma committed Oct 9, 2010
1 parent 5077d37 commit b83c74f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/s3/bucket.rb
Expand Up @@ -104,6 +104,15 @@ def location_constraint
def list_bucket(options = {})
response = bucket_request(:get, :params => options)
objects_attributes = parse_list_bucket_result(response.body)

# If there are more than 1000 objects S3 truncates listing
# and we need to request another listing for the remaining objects.
while parse_is_truncated(response.body)
marker = objects_attributes.last[:key]
response = bucket_request(:get, :params => options.merge(:marker => marker))
objects_attributes += parse_list_bucket_result(response.body)
end

objects_attributes.map { |object_attributes| Object.send(:new, self, object_attributes) }
end

Expand Down
4 changes: 4 additions & 0 deletions lib/s3/parser.rb
Expand Up @@ -44,5 +44,9 @@ def parse_error(xml)
message = document.elements["Error/Message"].text
[code, message]
end

def parse_is_truncated xml
rexml_document(xml).elements["ListBucketResult/IsTruncated"].text =='true'
end
end
end

0 comments on commit b83c74f

Please sign in to comment.