|
13 | 13 | // limitations under the License. |
14 | 14 |
|
15 | 15 | #include "google/cloud/storage/internal/async/writer_connection_impl.h" |
| 16 | +#include "google/cloud/storage/async/options.h" |
| 17 | +#include "google/cloud/storage/hashing_options.h" |
16 | 18 | #include "google/cloud/storage/internal/async/handle_redirect_error.h" |
17 | 19 | #include "google/cloud/storage/internal/async/partial_upload.h" |
18 | 20 | #include "google/cloud/storage/internal/async/write_payload_impl.h" |
19 | 21 | #include "google/cloud/storage/internal/grpc/ctype_cord_workaround.h" |
20 | 22 | #include "google/cloud/storage/internal/grpc/object_metadata_parser.h" |
21 | 23 | #include "google/cloud/storage/internal/grpc/object_request_parser.h" |
22 | | -#include "google/cloud/storage/async/options.h" |
23 | | -#include "google/cloud/storage/hashing_options.h" |
24 | 24 | #include "google/cloud/internal/make_status.h" |
25 | 25 |
|
26 | 26 | namespace google { |
@@ -147,19 +147,18 @@ AsyncWriterConnectionImpl::Finalize(storage::WritePayload payload) { |
147 | 147 | auto merged = google::cloud::internal::MergeOptions( |
148 | 148 | current_options, options_ ? *options_ : google::cloud::Options{}); |
149 | 149 |
|
150 | | - // Default to letting the internal hash function compute and send the checksum. |
| 150 | + // Default to letting the internal hash function compute and send the |
| 151 | + // checksum. |
151 | 152 | auto action = PartialUpload::kFinalizeWithChecksum; |
152 | 153 |
|
153 | | - if (is_append || current_options.has<google::cloud::storage::UseCrc32cValueOption>()) { |
| 154 | + if (is_append || merged.has<google::cloud::storage::UseCrc32cValueOption>()) { |
| 155 | + // If it's an appendable upload, or the user manually specified an expected |
| 156 | + // checksum, we manually inject it and use `kFinalize` so the internal hash |
| 157 | + // function doesn't compute and overwrite it with a partial or local hash. |
154 | 158 | if (merged.has<google::cloud::storage::UseCrc32cValueOption>()) { |
155 | 159 | write.mutable_object_checksums()->set_crc32c( |
156 | 160 | merged.get<google::cloud::storage::UseCrc32cValueOption>()); |
157 | 161 | } |
158 | | - // For appendable uploads, the internal hash function only sees the chunks uploaded |
159 | | - // in this stream, not the full object. We use `kFinalize` to avoid sending this |
160 | | - // partial hash, which would otherwise fail validation. |
161 | | - // If the user specified a manual expected checksum in `current_options`, we must |
162 | | - // also use `kFinalize` so the internal hash function doesn't overwrite it. |
163 | 162 | action = PartialUpload::kFinalize; |
164 | 163 | } |
165 | 164 |
|
|
0 commit comments