From eb75723f87571bc45b37302bb6cf1595d29aef45 Mon Sep 17 00:00:00 2001 From: Kevin Menard Date: Tue, 20 Dec 2011 15:59:23 -0500 Subject: [PATCH] [aws|storage|test] Deal with suspended buckets properly. --- lib/fog/aws/requests/storage/delete_object.rb | 9 ++++++++- lib/fog/aws/requests/storage/put_object.rb | 13 ++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/fog/aws/requests/storage/delete_object.rb b/lib/fog/aws/requests/storage/delete_object.rb index 5a9cc57dd..d8603df7c 100644 --- a/lib/fog/aws/requests/storage/delete_object.rb +++ b/lib/fog/aws/requests/storage/delete_object.rb @@ -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 diff --git a/lib/fog/aws/requests/storage/put_object.rb b/lib/fog/aws/requests/storage/put_object.rb index 684450eac..5cc087bc2 100644 --- a/lib/fog/aws/requests/storage/put_object.rb +++ b/lib/fog/aws/requests/storage/put_object.rb @@ -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]