Skip to content

Commit

Permalink
Use the options passed to S3Object.copy, supporting reduced redundancy
Browse files Browse the repository at this point in the history
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
Marcel M. Cary committed Nov 9, 2011
1 parent 5cd500f commit bd25b25
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/aws/s3/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions test/object_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bd25b25

Please sign in to comment.