From bbec81c4c9c75ab2db93dc0a1e4eb761e054ee84 Mon Sep 17 00:00:00 2001 From: Frederick Cheung Date: Sun, 2 Sep 2012 12:46:57 +0100 Subject: [PATCH] [AWS|Glacier] make 1.8.7 friendly --- lib/fog/aws/glacier.rb | 10 +++++++--- lib/fog/aws/requests/glacier/abort_multipart_upload.rb | 2 +- lib/fog/aws/requests/glacier/delete_archive.rb | 2 +- lib/fog/aws/requests/glacier/delete_vault.rb | 2 +- .../glacier/delete_vault_notification_configuration.rb | 2 +- lib/fog/aws/requests/glacier/describe_vault.rb | 2 +- lib/fog/aws/requests/glacier/get_job_output.rb | 2 +- .../glacier/get_vault_notification_configuration.rb | 2 +- .../aws/requests/glacier/initiate_multipart_upload.rb | 2 +- tests/aws/requests/glacier/tree_hash_tests.rb | 4 +++- 10 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/fog/aws/glacier.rb b/lib/fog/aws/glacier.rb index 7da51f2ed..7904a955c 100644 --- a/lib/fog/aws/glacier.rb +++ b/lib/fog/aws/glacier.rb @@ -70,10 +70,14 @@ module Fog if body.respond_to? :byteslice digests_for_part = chunk_count.times.collect {|chunk_index| Digest::SHA256.digest(body.byteslice(chunk_index * MEGABYTE, MEGABYTE))} else - old_encoding = body.encoding - body.force_encoding('BINARY') + if body.respond_to? :encoding + old_encoding = body.encoding + body.force_encoding('BINARY') + end digests_for_part = chunk_count.times.collect {|chunk_index| Digest::SHA256.digest(body.slice(chunk_index * MEGABYTE, MEGABYTE))} - body.force_encoding(old_encoding) + if body.respond_to? :encoding + body.force_encoding(old_encoding) + end end reduce_digests(digests_for_part) end diff --git a/lib/fog/aws/requests/glacier/abort_multipart_upload.rb b/lib/fog/aws/requests/glacier/abort_multipart_upload.rb index 79406f57c..a9903afc3 100644 --- a/lib/fog/aws/requests/glacier/abort_multipart_upload.rb +++ b/lib/fog/aws/requests/glacier/abort_multipart_upload.rb @@ -25,7 +25,7 @@ module Fog :idempotent => true, :headers => {}, :method => :delete, - :path => path, + :path => path ) end end diff --git a/lib/fog/aws/requests/glacier/delete_archive.rb b/lib/fog/aws/requests/glacier/delete_archive.rb index d113fe9c7..c6cb2caf5 100644 --- a/lib/fog/aws/requests/glacier/delete_archive.rb +++ b/lib/fog/aws/requests/glacier/delete_archive.rb @@ -25,7 +25,7 @@ module Fog :idempotent => true, :headers => {}, :method => :delete, - :path => path, + :path => path ) end end diff --git a/lib/fog/aws/requests/glacier/delete_vault.rb b/lib/fog/aws/requests/glacier/delete_vault.rb index 101c2326b..6e0a96491 100644 --- a/lib/fog/aws/requests/glacier/delete_vault.rb +++ b/lib/fog/aws/requests/glacier/delete_vault.rb @@ -24,7 +24,7 @@ module Fog :idempotent => true, :headers => {}, :method => :delete, - :path => path, + :path => path ) end end diff --git a/lib/fog/aws/requests/glacier/delete_vault_notification_configuration.rb b/lib/fog/aws/requests/glacier/delete_vault_notification_configuration.rb index 8c495f49b..f230e21e3 100644 --- a/lib/fog/aws/requests/glacier/delete_vault_notification_configuration.rb +++ b/lib/fog/aws/requests/glacier/delete_vault_notification_configuration.rb @@ -23,7 +23,7 @@ module Fog :idempotent => true, :headers => {}, :method => :delete, - :path => path, + :path => path ) end end diff --git a/lib/fog/aws/requests/glacier/describe_vault.rb b/lib/fog/aws/requests/glacier/describe_vault.rb index 2f823c892..c3a26c57a 100644 --- a/lib/fog/aws/requests/glacier/describe_vault.rb +++ b/lib/fog/aws/requests/glacier/describe_vault.rb @@ -24,7 +24,7 @@ module Fog :idempotent => true, :headers => {}, :method => :get, - :path => path, + :path => path ) end end diff --git a/lib/fog/aws/requests/glacier/get_job_output.rb b/lib/fog/aws/requests/glacier/get_job_output.rb index 3aa83b574..7f353599e 100644 --- a/lib/fog/aws/requests/glacier/get_job_output.rb +++ b/lib/fog/aws/requests/glacier/get_job_output.rb @@ -31,7 +31,7 @@ module Fog :idempotent => true, :headers => headers, :method => :get, - :path => path, + :path => path )) end end diff --git a/lib/fog/aws/requests/glacier/get_vault_notification_configuration.rb b/lib/fog/aws/requests/glacier/get_vault_notification_configuration.rb index 67f30f534..c88631fb9 100644 --- a/lib/fog/aws/requests/glacier/get_vault_notification_configuration.rb +++ b/lib/fog/aws/requests/glacier/get_vault_notification_configuration.rb @@ -24,7 +24,7 @@ module Fog :idempotent => true, :headers => {}, :method => :get, - :path => path, + :path => path ) end end diff --git a/lib/fog/aws/requests/glacier/initiate_multipart_upload.rb b/lib/fog/aws/requests/glacier/initiate_multipart_upload.rb index 362cdfb46..912ca33ad 100644 --- a/lib/fog/aws/requests/glacier/initiate_multipart_upload.rb +++ b/lib/fog/aws/requests/glacier/initiate_multipart_upload.rb @@ -28,7 +28,7 @@ module Fog :expects => 201, :headers => headers, :method => 'POST', - :path => path, + :path => path ) end end diff --git a/tests/aws/requests/glacier/tree_hash_tests.rb b/tests/aws/requests/glacier/tree_hash_tests.rb index 03a0300ed..292bcc35b 100644 --- a/tests/aws/requests/glacier/tree_hash_tests.rb +++ b/tests/aws/requests/glacier/tree_hash_tests.rb @@ -5,7 +5,9 @@ Shindo.tests('AWS::Glacier | glacier tree hash calcuation', ['aws']) do end tests('tree_hash(multibyte characters)') do - body = ("\xC2\xA1".force_encoding('UTF-8') * 1024*1024) + body = ("\xC2\xA1" * 1024*1024) + body.force_encoding('UTF-8') if body.respond_to? :encoding + expected = Digest::SHA256.hexdigest( Digest::SHA256.digest("\xC2\xA1" * 1024*512) + Digest::SHA256.digest("\xC2\xA1" * 1024*512) )