Skip to content

Commit bb22e44

Browse files
committed
notes on checksums
1 parent f5309cf commit bb22e44

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/aws-cpp-sdk-transfer/include/aws/transfer/TransferHandle.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,12 @@ namespace Aws
303303
const Aws::String GetEtag() const { std::lock_guard<std::mutex> locker(m_getterSetterLock); return m_etag; }
304304
void SetEtag(const Aws::String& etag) { std::lock_guard<std::mutex> locker(m_getterSetterLock); m_etag = etag; }
305305

306+
/**
307+
* (Download only) Checksum algorithm used for download
308+
*/
309+
Aws::S3::Model::ChecksumAlgorithm GetChecksumAlgorithm() const { std::lock_guard<std::mutex> locker(m_getterSetterLock); return m_checksumAlgorithm; }
310+
void SetChecksumAlgorithm (const Aws::S3::Model::ChecksumAlgorithm& checksumAlgorithm) { std::lock_guard<std::mutex> locker(m_getterSetterLock); m_checksumAlgorithm = checksumAlgorithm; }
311+
306312
/**
307313
* Upload or Download?
308314
*/
@@ -430,6 +436,7 @@ namespace Aws
430436
mutable std::condition_variable m_waitUntilFinishedSignal;
431437
mutable std::mutex m_getterSetterLock;
432438
Aws::String m_checksum;
439+
Aws::S3::Model::ChecksumAlgorithm m_checksumAlgorithm;
433440
};
434441

435442
AWS_TRANSFER_API Aws::OStream& operator << (Aws::OStream& s, TransferStatus status);

src/aws-cpp-sdk-transfer/source/transfer/TransferManager.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,18 @@ namespace Aws
10001000
handle->SetContentType(headObjectOutcome.GetResult().GetContentType());
10011001
handle->SetMetadata(headObjectOutcome.GetResult().GetMetadata());
10021002
handle->SetEtag(headObjectOutcome.GetResult().GetETag());
1003+
if (headObjectOutcome.GetResult().GetChecksumType() == Aws::S3::Model::ChecksumType::FULL_OBJECT) {
1004+
if (!headObjectOutcome.GetResult().GetChecksumCRC32C().empty()) {
1005+
handle->SetChecksum(headObjectOutcome.GetResult().GetChecksumCRC32C());
1006+
handle->SetChecksumAlgorithm(S3::Model::ChecksumAlgorithm::CRC32C);
1007+
} else if (!headObjectOutcome.GetResult().GetChecksumCRC32().empty()) {
1008+
handle->SetChecksum(headObjectOutcome.GetResult().GetChecksumCRC32());
1009+
handle->SetChecksumAlgorithm(S3::Model::ChecksumAlgorithm::CRC32);
1010+
} else if (!headObjectOutcome.GetResult().GetChecksumCRC64NVME().empty()) {
1011+
handle->SetChecksum(headObjectOutcome.GetResult().GetChecksumCRC64NVME());
1012+
handle->SetChecksumAlgorithm(S3::Model::ChecksumAlgorithm::CRC64NVME);
1013+
}
1014+
}
10031015
/* When bucket versioning is suspended, head object will return "null" for unversioned object.
10041016
* Send following GetObject with "null" as versionId will result in 403 access denied error if your IAM role or policy
10051017
* doesn't have GetObjectVersion permission.
@@ -1147,6 +1159,12 @@ namespace Aws
11471159
handle->UpdateStatus(DetermineIfFailedOrCanceled(*handle));
11481160
TriggerTransferStatusUpdatedCallback(handle);
11491161
}
1162+
// TODO: combine and check checksums
1163+
for (const auto& part : handle->GetCompletedParts()) {
1164+
// std::map with int index SHOULD BE ordered
1165+
part.second->GetChecksum();
1166+
// TODO: combine all checksums from all the parts right here
1167+
}
11501168
}
11511169

11521170
void TransferManager::HandleGetObjectResponse(const Aws::S3::S3Client* client,
@@ -1204,7 +1222,20 @@ namespace Aws
12041222

12051223
Aws::String errMsg{handle->WritePartToDownloadStream(bufferStream, partState->GetRangeBegin())};
12061224
if (errMsg.empty()) {
1207-
handle->ChangePartToCompleted(partState, outcome.GetResult().GetETag());
1225+
partState->SetChecksum([&]() -> Aws::String {
1226+
if (m_transferConfig.checksumAlgorithm == S3::Model::ChecksumAlgorithm::CRC32) {
1227+
return outcome.GetResult().GetChecksumCRC32();
1228+
}
1229+
if (m_transferConfig.checksumAlgorithm == S3::Model::ChecksumAlgorithm::CRC32C) {
1230+
return outcome.GetResult().GetChecksumCRC32C();
1231+
}
1232+
if (m_transferConfig.checksumAlgorithm == S3::Model::ChecksumAlgorithm::CRC64NVME) {
1233+
return outcome.GetResult().GetChecksumCRC64NVME();
1234+
}
1235+
// Return empty checksum for not set.
1236+
return "";
1237+
}());
1238+
handle->ChangePartToCompleted(partState, outcome.GetResult().GetETag());
12081239
} else {
12091240
Aws::Client::AWSError<Aws::S3::S3Errors> error(Aws::S3::S3Errors::INTERNAL_FAILURE,
12101241
"InternalFailure", errMsg, false);

0 commit comments

Comments
 (0)