Permalink
Browse files

Use the options passed to S3Object.copy, supporting reduced redundancy

I need to enable reduced redundancy on some existing S3 objects.
The typical way to do this is copy the object within S3, supplying the
new storage-class (reduced redundancy) as an option to the copy.
However, aws-s3 is ignoring the copy options, instead only using the
default_options to specify the copy-source.

Update the copy method to merge the copy-source options with the passed
options, so that storage-class can be specified.
  • Loading branch information...
1 parent 5cd500f commit bd25b25c5a7318dcf70da1adb9d53553b93d1237 Marcel M. Cary committed Nov 9, 2011
Showing with 16 additions and 1 deletion.
  1. +1 −1 lib/aws/s3/object.rb
  2. +15 −0 test/object_test.rb
View
2 lib/aws/s3/object.rb
@@ -184,7 +184,7 @@ def copy(key, copy_key, bucket = nil, options = {})
source_key = path!(bucket, key)
default_options = {'x-amz-copy-source' => source_key}
target_key = path!(bucket, copy_key)
- returning put(target_key, default_options) do
+ returning put(target_key, default_options.merge(options)) do
acl(copy_key, bucket, acl(key, bucket)) if options[:copy_acl]
end
end
View
15 test/object_test.rb
@@ -148,6 +148,21 @@ def test_fetching_information_about_an_object_that_does_not_exist_raises_no_such
S3Object.about('asdfasdfasdfas-this-does-not-exist', 'bucket does not matter')
end
end
+ def test_copy_options_are_used
+ options = {'x-amz-storage-class' => 'REDUCED_REDUNDANCY'}
+ resp = FakeResponse.new
+
+ connection = flexmock('Mock connection') do |mock|
+ mock.should_receive(:request).
+ # The storage-class key must be passed to connection.request(:put, ...)
+ with(:put, '/some-bucket/new', hsh(options), any, any).
+ and_return(resp)
+ end
+ flexmock(S3Object).should_receive(:connection).and_return(connection)
+
+ result = S3Object.copy('old', 'new', 'some-bucket', options)
+ assert_equal resp.code, result.code
+ end
end
class MetadataTest < Test::Unit::TestCase

0 comments on commit bd25b25

Please sign in to comment.