Skip to content

Commit 713d027

Browse files
committed
Update ListObjectsV2 response structure to include unique common prefixes in KeyCount calculation
- Modified the response body to ensure that the 'KeyCount' accurately reflects the total number of objects and unique common prefixes. - Adjusted the handling of 'CommonPrefixes' to use a unique set, improving the integrity of the response data.
1 parent 580b4a6 commit 713d027

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/fog/aws/requests/storage/list_objects_v2.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,14 @@ def list_objects_v2(bucket_name, options = {})
9999
next_token = truncated_contents.size != contents.size ? truncated_contents.last['Key'] : nil
100100

101101
response.status = 200
102+
common_prefixes_uniq = common_prefixes.uniq
102103
response.body = {
103-
'CommonPrefixes' => common_prefixes.uniq,
104+
'CommonPrefixes' => common_prefixes_uniq,
104105
'Contents' => truncated_contents,
105106
'IsTruncated' => truncated_contents.size != contents.size,
106107
'ContinuationToken' => continuation_token,
107108
'NextContinuationToken' => next_token,
108-
'KeyCount' => truncated_contents.size,
109+
'KeyCount' => truncated_contents.size + common_prefixes_uniq.size,
109110
'MaxKeys' => max_keys,
110111
'Name' => bucket['Name'],
111112
'Prefix' => prefix,
@@ -114,7 +115,7 @@ def list_objects_v2(bucket_name, options = {})
114115
if max_keys && max_keys < response.body['Contents'].length
115116
response.body['IsTruncated'] = true
116117
response.body['Contents'] = response.body['Contents'][0...max_keys]
117-
response.body['KeyCount'] = response.body['Contents'].size
118+
response.body['KeyCount'] = response.body['Contents'].size + response.body['CommonPrefixes'].size
118119
end
119120
else
120121
response.status = 404

0 commit comments

Comments
 (0)