1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[aws|storage|test] Deal with suspended buckets properly.

This commit is contained in:
Kevin Menard 2011-12-20 15:59:23 -05:00
parent f391ae7b94
commit eb75723f87
2 changed files with 18 additions and 4 deletions

View file

@ -65,11 +65,18 @@ module Fog
delete_marker = {
:delete_marker => true,
'Key' => object_name,
'VersionId' => Fog::Mock.random_base64(32),
'VersionId' => bucket[:versioning] == 'Enabled' ? Fog::Mock.random_base64(32) : 'null',
'Last-Modified' => Fog::Time.now.to_date_header
}
# When versioning is suspended, a delete marker is placed if the last object ID is not the value 'null',
# otherwise the last object is replaced.
if bucket[:versioning] == 'Suspended' && bucket[:objects][object_name].last['VersionId'] == 'null'
bucket[:objects][object_name].pop
end
bucket[:objects][object_name] << delete_marker
response.headers['x-amz-delete-marker'] = 'true'
response.headers['x-amz-version-id'] = delete_marker['VersionId']
end

View file

@ -32,9 +32,9 @@ module Fog
def put_object(bucket_name, object_name, data, options = {})
data = Fog::Storage.parse_data(data)
headers = data[:headers].merge!(options)
request({
:body => data[:body],
:expects => 200,
request({ :body => data[:body],
:expects => 200,
:headers => headers,
:host => "#{bucket_name}.#{@host}",
:idempotent => true,
@ -83,6 +83,13 @@ module Fog
if bucket[:versioning]
bucket[:objects][object_name] ||= []
# When versioning is suspended, putting an object will create a new 'null' version if the latest version
# is a value other than 'null', otherwise it will replace the latest version.
if bucket[:versioning] == 'Suspended' && bucket[:objects][object_name].last['VersionId'] == 'null'
bucket[:objects][object_name].pop
end
bucket[:objects][object_name] << object
else
bucket[:objects][object_name] = [object]