Skip to content

Commit

Permalink
Another fix to incrementally_list_bucket: guard against non-existence…
Browse files Browse the repository at this point in the history
… of :'max_keys' option.

git-svn-id: https://wush.net/svn/rightscale/right_aws/trunk@3133 9f0cbaf6-ce18-0410-ad37-d14a22affa91
  • Loading branch information
trbryan committed Mar 19, 2008
1 parent 05bfc09 commit 992621c
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions lib/s3/right_s3_interface.rb
Expand Up @@ -283,27 +283,38 @@ def incrementally_list_bucket(bucket, options={}, headers={}, &block)
response = request_info(req_hash, S3ImprovedListBucketParser.new(:logger => @logger))
there_are_more_keys = response[:is_truncated]
if(there_are_more_keys)
if(response[:next_marker])
# Dup from response so that no one can mess with these values in the
# yield block
internal_options[:marker] = response[:next_marker].dup
else
if( response[:contents].last[:key] > response[:common_prefixes].last )
internal_options[:marker] = response[:contents].last[:key].dup
else
internal_options[:marker] = response[:common_prefixes].last.dup
end
end
internal_options[:marker] = decide_marker(response)
total_results = response[:contents].length + response[:common_prefixes].length
internal_options[:'max-keys'] ? (internal_options[:'max-keys'] -= total_results) : nil
end
yield response
end while there_are_more_keys && internal_options[:'max-keys'] > 0
end while there_are_more_keys && under_max_keys(internal_options)
true
rescue
on_exception
end


private
def decide_marker(response)
return response[:next_marker].dup if response[:next_marker]
last_key = response[:contents].last[:key]
last_prefix = response[:common_prefixes].last
if(!last_key)
return nil if(!last_prefix)
last_prefix.dup
elsif(!last_prefix)
last_key.dup
else
last_key > last_prefix ? last_key.dup : last_prefix.dup
end
end

def under_max_keys(internal_options)
internal_options[:'max-keys'] ? internal_options[:'max-keys'] > 0 : true
end

public
# Saves object to Amazon. Returns +true+ or an exception.
# Any header starting with AMAZON_METADATA_PREFIX is considered
# user metadata. It will be stored with the object and returned
Expand Down

0 comments on commit 992621c

Please sign in to comment.