aws-sdk-s3 1.45.0 → 1.143.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +1106 -0
  3. data/LICENSE.txt +202 -0
  4. data/VERSION +1 -0
  5. data/lib/aws-sdk-s3/bucket.rb +784 -98
  6. data/lib/aws-sdk-s3/bucket_acl.rb +64 -18
  7. data/lib/aws-sdk-s3/bucket_cors.rb +79 -18
  8. data/lib/aws-sdk-s3/bucket_lifecycle.rb +66 -20
  9. data/lib/aws-sdk-s3/bucket_lifecycle_configuration.rb +68 -20
  10. data/lib/aws-sdk-s3/bucket_logging.rb +68 -16
  11. data/lib/aws-sdk-s3/bucket_notification.rb +52 -20
  12. data/lib/aws-sdk-s3/bucket_policy.rb +107 -17
  13. data/lib/aws-sdk-s3/bucket_region_cache.rb +2 -0
  14. data/lib/aws-sdk-s3/bucket_request_payment.rb +60 -15
  15. data/lib/aws-sdk-s3/bucket_tagging.rb +71 -18
  16. data/lib/aws-sdk-s3/bucket_versioning.rb +133 -17
  17. data/lib/aws-sdk-s3/bucket_website.rb +78 -21
  18. data/lib/aws-sdk-s3/client.rb +12610 -902
  19. data/lib/aws-sdk-s3/client_api.rb +1086 -191
  20. data/lib/aws-sdk-s3/customizations/bucket.rb +56 -37
  21. data/lib/aws-sdk-s3/customizations/errors.rb +27 -0
  22. data/lib/aws-sdk-s3/customizations/multipart_upload.rb +2 -0
  23. data/lib/aws-sdk-s3/customizations/object.rb +282 -68
  24. data/lib/aws-sdk-s3/customizations/object_summary.rb +5 -0
  25. data/lib/aws-sdk-s3/customizations/types/list_object_versions_output.rb +2 -0
  26. data/lib/aws-sdk-s3/customizations/types/permanent_redirect.rb +26 -0
  27. data/lib/aws-sdk-s3/customizations.rb +11 -1
  28. data/lib/aws-sdk-s3/encryption/client.rb +28 -7
  29. data/lib/aws-sdk-s3/encryption/decrypt_handler.rb +71 -29
  30. data/lib/aws-sdk-s3/encryption/default_cipher_provider.rb +43 -5
  31. data/lib/aws-sdk-s3/encryption/default_key_provider.rb +2 -0
  32. data/lib/aws-sdk-s3/encryption/encrypt_handler.rb +13 -2
  33. data/lib/aws-sdk-s3/encryption/errors.rb +2 -0
  34. data/lib/aws-sdk-s3/encryption/io_auth_decrypter.rb +2 -0
  35. data/lib/aws-sdk-s3/encryption/io_decrypter.rb +11 -3
  36. data/lib/aws-sdk-s3/encryption/io_encrypter.rb +2 -0
  37. data/lib/aws-sdk-s3/encryption/key_provider.rb +2 -0
  38. data/lib/aws-sdk-s3/encryption/kms_cipher_provider.rb +46 -11
  39. data/lib/aws-sdk-s3/encryption/materials.rb +8 -6
  40. data/lib/aws-sdk-s3/encryption/utils.rb +25 -0
  41. data/lib/aws-sdk-s3/encryption.rb +4 -0
  42. data/lib/aws-sdk-s3/encryptionV2/client.rb +570 -0
  43. data/lib/aws-sdk-s3/encryptionV2/decrypt_handler.rb +223 -0
  44. data/lib/aws-sdk-s3/encryptionV2/default_cipher_provider.rb +170 -0
  45. data/lib/aws-sdk-s3/encryptionV2/default_key_provider.rb +40 -0
  46. data/lib/aws-sdk-s3/encryptionV2/encrypt_handler.rb +65 -0
  47. data/lib/aws-sdk-s3/encryptionV2/errors.rb +37 -0
  48. data/lib/aws-sdk-s3/encryptionV2/io_auth_decrypter.rb +58 -0
  49. data/lib/aws-sdk-s3/encryptionV2/io_decrypter.rb +37 -0
  50. data/lib/aws-sdk-s3/encryptionV2/io_encrypter.rb +73 -0
  51. data/lib/aws-sdk-s3/encryptionV2/key_provider.rb +31 -0
  52. data/lib/aws-sdk-s3/encryptionV2/kms_cipher_provider.rb +173 -0
  53. data/lib/aws-sdk-s3/encryptionV2/materials.rb +60 -0
  54. data/lib/aws-sdk-s3/encryptionV2/utils.rb +103 -0
  55. data/lib/aws-sdk-s3/encryption_v2.rb +23 -0
  56. data/lib/aws-sdk-s3/endpoint_parameters.rb +178 -0
  57. data/lib/aws-sdk-s3/endpoint_provider.rb +591 -0
  58. data/lib/aws-sdk-s3/endpoints.rb +2590 -0
  59. data/lib/aws-sdk-s3/errors.rb +123 -1
  60. data/lib/aws-sdk-s3/event_streams.rb +8 -1
  61. data/lib/aws-sdk-s3/express_credentials.rb +55 -0
  62. data/lib/aws-sdk-s3/express_credentials_cache.rb +30 -0
  63. data/lib/aws-sdk-s3/express_credentials_provider.rb +36 -0
  64. data/lib/aws-sdk-s3/file_downloader.rb +176 -44
  65. data/lib/aws-sdk-s3/file_part.rb +11 -6
  66. data/lib/aws-sdk-s3/file_uploader.rb +39 -18
  67. data/lib/aws-sdk-s3/legacy_signer.rb +17 -25
  68. data/lib/aws-sdk-s3/multipart_file_uploader.rb +78 -20
  69. data/lib/aws-sdk-s3/multipart_stream_uploader.rb +56 -18
  70. data/lib/aws-sdk-s3/multipart_upload.rb +242 -32
  71. data/lib/aws-sdk-s3/multipart_upload_error.rb +2 -0
  72. data/lib/aws-sdk-s3/multipart_upload_part.rb +367 -45
  73. data/lib/aws-sdk-s3/object.rb +2191 -227
  74. data/lib/aws-sdk-s3/object_acl.rb +103 -25
  75. data/lib/aws-sdk-s3/object_copier.rb +9 -5
  76. data/lib/aws-sdk-s3/object_multipart_copier.rb +43 -19
  77. data/lib/aws-sdk-s3/object_summary.rb +1811 -208
  78. data/lib/aws-sdk-s3/object_version.rb +452 -80
  79. data/lib/aws-sdk-s3/plugins/accelerate.rb +17 -64
  80. data/lib/aws-sdk-s3/plugins/arn.rb +70 -0
  81. data/lib/aws-sdk-s3/plugins/bucket_dns.rb +7 -43
  82. data/lib/aws-sdk-s3/plugins/bucket_name_restrictions.rb +20 -3
  83. data/lib/aws-sdk-s3/plugins/dualstack.rb +7 -50
  84. data/lib/aws-sdk-s3/plugins/endpoints.rb +274 -0
  85. data/lib/aws-sdk-s3/plugins/expect_100_continue.rb +5 -4
  86. data/lib/aws-sdk-s3/plugins/express_session_auth.rb +91 -0
  87. data/lib/aws-sdk-s3/plugins/get_bucket_location_fix.rb +3 -1
  88. data/lib/aws-sdk-s3/plugins/http_200_errors.rb +11 -3
  89. data/lib/aws-sdk-s3/plugins/iad_regional_endpoint.rb +44 -0
  90. data/lib/aws-sdk-s3/plugins/location_constraint.rb +5 -1
  91. data/lib/aws-sdk-s3/plugins/md5s.rb +35 -30
  92. data/lib/aws-sdk-s3/plugins/redirects.rb +2 -0
  93. data/lib/aws-sdk-s3/plugins/s3_host_id.rb +2 -0
  94. data/lib/aws-sdk-s3/plugins/s3_signer.rb +56 -92
  95. data/lib/aws-sdk-s3/plugins/skip_whole_multipart_get_checksums.rb +31 -0
  96. data/lib/aws-sdk-s3/plugins/sse_cpk.rb +3 -1
  97. data/lib/aws-sdk-s3/plugins/streaming_retry.rb +139 -0
  98. data/lib/aws-sdk-s3/plugins/url_encoded_keys.rb +2 -0
  99. data/lib/aws-sdk-s3/presigned_post.rb +160 -99
  100. data/lib/aws-sdk-s3/presigner.rb +171 -80
  101. data/lib/aws-sdk-s3/resource.rb +120 -8
  102. data/lib/aws-sdk-s3/types.rb +11353 -4225
  103. data/lib/aws-sdk-s3/waiters.rb +67 -1
  104. data/lib/aws-sdk-s3.rb +16 -6
  105. data/sig/bucket.rbs +212 -0
  106. data/sig/bucket_acl.rbs +78 -0
  107. data/sig/bucket_cors.rbs +69 -0
  108. data/sig/bucket_lifecycle.rbs +88 -0
  109. data/sig/bucket_lifecycle_configuration.rbs +111 -0
  110. data/sig/bucket_logging.rbs +76 -0
  111. data/sig/bucket_notification.rbs +114 -0
  112. data/sig/bucket_policy.rbs +59 -0
  113. data/sig/bucket_request_payment.rbs +54 -0
  114. data/sig/bucket_tagging.rbs +65 -0
  115. data/sig/bucket_versioning.rbs +77 -0
  116. data/sig/bucket_website.rbs +93 -0
  117. data/sig/client.rbs +2360 -0
  118. data/sig/errors.rbs +34 -0
  119. data/sig/multipart_upload.rbs +110 -0
  120. data/sig/multipart_upload_part.rbs +105 -0
  121. data/sig/object.rbs +436 -0
  122. data/sig/object_acl.rbs +86 -0
  123. data/sig/object_summary.rbs +334 -0
  124. data/sig/object_version.rbs +131 -0
  125. data/sig/resource.rbs +124 -0
  126. data/sig/types.rbs +2562 -0
  127. data/sig/waiters.rbs +83 -0
  128. metadata +68 -15
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathname'
2
4
 
3
5
  module Aws
@@ -5,44 +7,49 @@ module Aws
5
7
  # @api private
6
8
  class FileUploader
7
9
 
8
- FIFTEEN_MEGABYTES = 15 * 1024 * 1024
10
+ ONE_HUNDRED_MEGABYTES = 100 * 1024 * 1024
9
11
 
12
+ # @param [Hash] options
10
13
  # @option options [Client] :client
11
- # @option options [Integer] :multipart_threshold Files greater than
12
- # `:multipart_threshold` bytes are uploaded using S3 multipart APIs.
14
+ # @option options [Integer] :multipart_threshold (104857600)
13
15
  def initialize(options = {})
14
16
  @options = options
15
17
  @client = options[:client] || Client.new
16
- @multipart_threshold = options[:multipart_threshold] || FIFTEEN_MEGABYTES
18
+ @multipart_threshold = options[:multipart_threshold] ||
19
+ ONE_HUNDRED_MEGABYTES
17
20
  end
18
21
 
19
22
  # @return [Client]
20
23
  attr_reader :client
21
24
 
22
- # @return [Integer] Files larger than this in bytes are uploaded
25
+ # @return [Integer] Files larger than or equal to this in bytes are uploaded
23
26
  # using a {MultipartFileUploader}.
24
27
  attr_reader :multipart_threshold
25
28
 
26
- # @param [String,Pathname,File,Tempfile] source
27
- # @option options [required,String] :bucket
28
- # @option options [required,String] :key
29
+ # @param [String, Pathname, File, Tempfile] source The file to upload.
30
+ # @option options [required, String] :bucket The bucket to upload to.
31
+ # @option options [required, String] :key The key for the object.
32
+ # @option options [Proc] :progress_callback
33
+ # A Proc that will be called when each chunk of the upload is sent.
34
+ # It will be invoked with [bytes_read], [total_sizes]
35
+ # @option options [Integer] :thread_count
36
+ # The thread count to use for multipart uploads. Ignored for
37
+ # objects smaller than the multipart threshold.
29
38
  # @return [void]
30
39
  def upload(source, options = {})
31
- if File.size(source) >= multipart_threshold
32
- MultipartFileUploader.new(@options).upload(source, options)
33
- else
34
- put_object(source, options)
40
+ Aws::Plugins::UserAgent.feature('s3-transfer') do
41
+ if File.size(source) >= multipart_threshold
42
+ MultipartFileUploader.new(@options).upload(source, options)
43
+ else
44
+ # remove multipart parameters not supported by put_object
45
+ options.delete(:thread_count)
46
+ put_object(source, options)
47
+ end
35
48
  end
36
49
  end
37
50
 
38
51
  private
39
52
 
40
- def put_object(source, options)
41
- open_file(source) do |file|
42
- @client.put_object(options.merge(body: file))
43
- end
44
- end
45
-
46
53
  def open_file(source)
47
54
  if String === source || Pathname === source
48
55
  File.open(source, 'rb') { |file| yield(file) }
@@ -51,6 +58,20 @@ module Aws
51
58
  end
52
59
  end
53
60
 
61
+ def put_object(source, options)
62
+ if (callback = options.delete(:progress_callback))
63
+ options[:on_chunk_sent] = single_part_progress(callback)
64
+ end
65
+ open_file(source) do |file|
66
+ @client.put_object(options.merge(body: file))
67
+ end
68
+ end
69
+
70
+ def single_part_progress(progress_callback)
71
+ proc do |_chunk, bytes_read, total_size|
72
+ progress_callback.call([bytes_read], [total_size])
73
+ end
74
+ end
54
75
  end
55
76
  end
56
77
  end
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'set'
2
4
  require 'time'
3
5
  require 'openssl'
4
6
  require 'cgi'
5
- require 'webrick/httputils'
6
7
  require 'aws-sdk-core/query'
7
8
 
8
9
  module Aws
@@ -155,33 +156,24 @@ module Aws
155
156
  end
156
157
 
157
158
  def uri_escape(s)
158
-
159
159
  #URI.escape(s)
160
160
 
161
- # URI.escape is deprecated, replacing it with escape from webrick
162
- # to squelch the massive number of warnings generated from Ruby.
163
- # The following script was used to determine the differences
164
- # between the various escape methods available. The webrick
165
- # escape only had two differences and it is available in the
166
- # standard lib.
167
- #
168
- # (0..255).each {|c|
169
- # s = [c].pack("C")
170
- # e = [
171
- # CGI.escape(s),
172
- # ERB::Util.url_encode(s),
173
- # URI.encode_www_form_component(s),
174
- # WEBrick::HTTPUtils.escape_form(s),
175
- # WEBrick::HTTPUtils.escape(s),
176
- # URI.escape(s),
177
- # ]
178
- # next if e.uniq.length == 1
179
- # puts("%5s %5s %5s %5s %5s %5s %5s" % ([s.inspect] + e))
180
- # }
181
- #
182
- WEBrick::HTTPUtils.escape(s).gsub('%5B', '[').gsub('%5D', ']')
161
+ # (0..255).each {|c|
162
+ # s = [c].pack("C")
163
+ # e = [
164
+ # CGI.escape(s),
165
+ # ERB::Util.url_encode(s),
166
+ # URI.encode_www_form_component(s),
167
+ # WEBrick::HTTPUtils.escape_form(s),
168
+ # WEBrick::HTTPUtils.escape(s),
169
+ # URI.escape(s),
170
+ # URI::DEFAULT_PARSER.escape(s)
171
+ # ]
172
+ # next if e.uniq.length == 1
173
+ # puts("%5s %5s %5s %5s %5s %5s %5s %5s" % ([s.inspect] + e))
174
+ # }
175
+ URI::DEFAULT_PARSER.escape(s)
183
176
  end
184
-
185
177
  end
186
178
  end
187
179
  end
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathname'
2
- require 'thread'
3
4
  require 'set'
4
5
 
5
6
  module Aws
@@ -16,14 +17,21 @@ module Aws
16
17
  THREAD_COUNT = 10
17
18
 
18
19
  # @api private
19
- CREATE_OPTIONS =
20
- Set.new(Client.api.operation(:create_multipart_upload).input.shape.member_names)
20
+ CREATE_OPTIONS = Set.new(
21
+ Client.api.operation(:create_multipart_upload).input.shape.member_names
22
+ )
23
+
24
+ COMPLETE_OPTIONS = Set.new(
25
+ Client.api.operation(:complete_multipart_upload).input.shape.member_names
26
+ )
21
27
 
22
28
  # @api private
23
- UPLOAD_PART_OPTIONS =
24
- Set.new(Client.api.operation(:upload_part).input.shape.member_names)
29
+ UPLOAD_PART_OPTIONS = Set.new(
30
+ Client.api.operation(:upload_part).input.shape.member_names
31
+ )
25
32
 
26
33
  # @option options [Client] :client
34
+ # @option options [Integer] :thread_count (THREAD_COUNT)
27
35
  def initialize(options = {})
28
36
  @client = options[:client] || Client.new
29
37
  @thread_count = options[:thread_count] || THREAD_COUNT
@@ -32,10 +40,13 @@ module Aws
32
40
  # @return [Client]
33
41
  attr_reader :client
34
42
 
35
- # @param [String,Pathname,File,Tempfile] source
36
- # @option options [required,String] :bucket
37
- # @option options [required,String] :key
38
- # @return [void]
43
+ # @param [String, Pathname, File, Tempfile] source The file to upload.
44
+ # @option options [required, String] :bucket The bucket to upload to.
45
+ # @option options [required, String] :key The key for the object.
46
+ # @option options [Proc] :progress_callback
47
+ # A Proc that will be called when each chunk of the upload is sent.
48
+ # It will be invoked with [bytes_read], [total_sizes]
49
+ # @return [Seahorse::Client::Response] - the CompleteMultipartUploadResponse
39
50
  def upload(source, options = {})
40
51
  if File.size(source) < MIN_PART_SIZE
41
52
  raise ArgumentError, FILE_TOO_SMALL
@@ -54,16 +65,17 @@ module Aws
54
65
 
55
66
  def complete_upload(upload_id, parts, options)
56
67
  @client.complete_multipart_upload(
57
- bucket: options[:bucket],
58
- key: options[:key],
59
- upload_id: upload_id,
60
- multipart_upload: { parts: parts })
68
+ **complete_opts(options).merge(
69
+ upload_id: upload_id,
70
+ multipart_upload: { parts: parts }
71
+ )
72
+ )
61
73
  end
62
74
 
63
75
  def upload_parts(upload_id, source, options)
64
76
  pending = PartList.new(compute_parts(upload_id, source, options))
65
77
  completed = PartList.new
66
- errors = upload_in_threads(pending, completed)
78
+ errors = upload_in_threads(pending, completed, options)
67
79
  if errors.empty?
68
80
  completed.to_a.sort_by { |part| part[:part_number] }
69
81
  else
@@ -93,7 +105,7 @@ module Aws
93
105
  part_number = 1
94
106
  parts = []
95
107
  while offset < size
96
- parts << upload_part_opts(options).merge({
108
+ parts << upload_part_opts(options).merge(
97
109
  upload_id: upload_id,
98
110
  part_number: part_number,
99
111
  body: FilePart.new(
@@ -101,7 +113,7 @@ module Aws
101
113
  offset: offset,
102
114
  size: part_size(size, default_part_size, offset)
103
115
  )
104
- })
116
+ )
105
117
  part_number += 1
106
118
  offset += default_part_size
107
119
  end
@@ -115,6 +127,13 @@ module Aws
115
127
  end
116
128
  end
117
129
 
130
+ def complete_opts(options)
131
+ COMPLETE_OPTIONS.inject({}) do |hash, key|
132
+ hash[key] = options[key] if options.key?(key)
133
+ hash
134
+ end
135
+ end
136
+
118
137
  def upload_part_opts(options)
119
138
  UPLOAD_PART_OPTIONS.inject({}) do |hash, key|
120
139
  hash[key] = options[key] if options.key?(key)
@@ -122,15 +141,32 @@ module Aws
122
141
  end
123
142
  end
124
143
 
125
- def upload_in_threads(pending, completed)
144
+ def upload_in_threads(pending, completed, options)
126
145
  threads = []
146
+ if (callback = options[:progress_callback])
147
+ progress = MultipartProgress.new(pending, callback)
148
+ end
127
149
  @thread_count.times do
128
150
  thread = Thread.new do
129
151
  begin
130
152
  while part = pending.shift
153
+ if progress
154
+ part[:on_chunk_sent] =
155
+ proc do |_chunk, bytes, _total|
156
+ progress.call(part[:part_number], bytes)
157
+ end
158
+ end
131
159
  resp = @client.upload_part(part)
132
160
  part[:body].close
133
- completed.push(etag: resp.etag, part_number: part[:part_number])
161
+ completed_part = {etag: resp.etag, part_number: part[:part_number]}
162
+
163
+ # get the requested checksum from the response
164
+ if part[:checksum_algorithm]
165
+ k = "checksum_#{part[:checksum_algorithm].downcase}".to_sym
166
+ completed_part[k] = resp[k]
167
+ end
168
+
169
+ completed.push(completed_part)
134
170
  end
135
171
  nil
136
172
  rescue => error
@@ -139,7 +175,6 @@ module Aws
139
175
  error
140
176
  end
141
177
  end
142
- thread.abort_on_exception = true
143
178
  threads << thread
144
179
  end
145
180
  threads.map(&:value).compact
@@ -177,11 +212,34 @@ module Aws
177
212
  @mutex.synchronize { @parts.clear }
178
213
  end
179
214
 
215
+ def size
216
+ @mutex.synchronize { @parts.size }
217
+ end
218
+
219
+ def part_sizes
220
+ @mutex.synchronize { @parts.map { |p| p[:body].size } }
221
+ end
222
+
180
223
  def to_a
181
224
  @mutex.synchronize { @parts.dup }
182
225
  end
183
226
 
184
227
  end
228
+
229
+ # @api private
230
+ class MultipartProgress
231
+ def initialize(parts, progress_callback)
232
+ @bytes_sent = Array.new(parts.size, 0)
233
+ @total_sizes = parts.part_sizes
234
+ @progress_callback = progress_callback
235
+ end
236
+
237
+ def call(part_number, bytes_read)
238
+ # part numbers start at 1
239
+ @bytes_sent[part_number - 1] = bytes_read
240
+ @progress_callback.call(@bytes_sent, @total_sizes)
241
+ end
242
+ end
185
243
  end
186
244
  end
187
- end
245
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'thread'
2
4
  require 'set'
3
5
  require 'tempfile'
@@ -24,6 +26,10 @@ module Aws
24
26
  UPLOAD_PART_OPTIONS =
25
27
  Set.new(Client.api.operation(:upload_part).input.shape.member_names)
26
28
 
29
+ # @api private
30
+ COMPLETE_UPLOAD_OPTIONS =
31
+ Set.new(Client.api.operation(:complete_multipart_upload).input.shape.member_names)
32
+
27
33
  # @option options [Client] :client
28
34
  def initialize(options = {})
29
35
  @client = options[:client] || Client.new
@@ -37,11 +43,13 @@ module Aws
37
43
 
38
44
  # @option options [required,String] :bucket
39
45
  # @option options [required,String] :key
40
- # @return [void]
46
+ # @return [Seahorse::Client::Response] - the CompleteMultipartUploadResponse
41
47
  def upload(options = {}, &block)
42
- upload_id = initiate_upload(options)
43
- parts = upload_parts(upload_id, options, &block)
44
- complete_upload(upload_id, parts, options)
48
+ Aws::Plugins::UserAgent.feature('s3-transfer') do
49
+ upload_id = initiate_upload(options)
50
+ parts = upload_parts(upload_id, options, &block)
51
+ complete_upload(upload_id, parts, options)
52
+ end
45
53
  end
46
54
 
47
55
  private
@@ -52,20 +60,34 @@ module Aws
52
60
 
53
61
  def complete_upload(upload_id, parts, options)
54
62
  @client.complete_multipart_upload(
55
- bucket: options[:bucket],
56
- key: options[:key],
57
- upload_id: upload_id,
58
- multipart_upload: { parts: parts })
63
+ **complete_opts(options).merge(
64
+ upload_id: upload_id,
65
+ multipart_upload: { parts: parts }
66
+ )
67
+ )
59
68
  end
60
69
 
61
70
  def upload_parts(upload_id, options, &block)
62
71
  completed = Queue.new
63
- errors = IO.pipe do |read_pipe, write_pipe|
64
- threads = upload_in_threads(read_pipe, completed, upload_part_opts(options).merge(upload_id: upload_id))
65
- block.call(write_pipe)
66
- write_pipe.close
67
- threads.map(&:value).compact
72
+ thread_errors = []
73
+ errors = begin
74
+ IO.pipe do |read_pipe, write_pipe|
75
+ threads = upload_in_threads(
76
+ read_pipe, completed,
77
+ upload_part_opts(options).merge(upload_id: upload_id),
78
+ thread_errors)
79
+ begin
80
+ block.call(write_pipe)
81
+ ensure
82
+ # Ensure the pipe is closed to avoid https://github.com/jruby/jruby/issues/6111
83
+ write_pipe.close
84
+ end
85
+ threads.map(&:value).compact
86
+ end
87
+ rescue => e
88
+ thread_errors + [e]
68
89
  end
90
+
69
91
  if errors.empty?
70
92
  Array.new(completed.size) { completed.pop }.sort_by { |part| part[:part_number] }
71
93
  else
@@ -102,9 +124,16 @@ module Aws
102
124
  end
103
125
  end
104
126
 
127
+ def complete_opts(options)
128
+ COMPLETE_UPLOAD_OPTIONS.inject({}) do |hash, key|
129
+ hash[key] = options[key] if options.key?(key)
130
+ hash
131
+ end
132
+ end
133
+
105
134
  def read_to_part_body(read_pipe)
106
135
  return if read_pipe.closed?
107
- temp_io = @tempfile ? Tempfile.new(TEMPFILE_PREIX) : StringIO.new
136
+ temp_io = @tempfile ? Tempfile.new(TEMPFILE_PREIX) : StringIO.new(String.new)
108
137
  temp_io.binmode
109
138
  bytes_copied = IO.copy_stream(read_pipe, temp_io, @part_size)
110
139
  temp_io.rewind
@@ -119,7 +148,7 @@ module Aws
119
148
  end
120
149
  end
121
150
 
122
- def upload_in_threads(read_pipe, completed, options)
151
+ def upload_in_threads(read_pipe, completed, options, thread_errors)
123
152
  mutex = Mutex.new
124
153
  part_number = 0
125
154
  @thread_count.times.map do
@@ -136,7 +165,14 @@ module Aws
136
165
  part_number: thread_part_number,
137
166
  )
138
167
  resp = @client.upload_part(part)
139
- completed << {etag: resp.etag, part_number: part[:part_number]}
168
+ completed_part = {etag: resp.etag, part_number: part[:part_number]}
169
+
170
+ # get the requested checksum from the response
171
+ if part[:checksum_algorithm]
172
+ k = "checksum_#{part[:checksum_algorithm].downcase}".to_sym
173
+ completed_part[k] = resp[k]
174
+ end
175
+ completed.push(completed_part)
140
176
  ensure
141
177
  if Tempfile === body
142
178
  body.close
@@ -149,11 +185,13 @@ module Aws
149
185
  nil
150
186
  rescue => error
151
187
  # keep other threads from uploading other parts
152
- mutex.synchronize { read_pipe.close_read }
188
+ mutex.synchronize do
189
+ thread_errors.push(error)
190
+ read_pipe.close_read unless read_pipe.closed?
191
+ end
153
192
  error
154
193
  end
155
194
  end
156
- thread.abort_on_exception = true
157
195
  thread
158
196
  end
159
197
  end