Skip to content

Commit 8ab471c

Browse files
committed
updaing comments
1 parent bef77d7 commit 8ab471c

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed

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

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,6 @@ namespace Aws
10061006

10071007
// Store full object checksum from HeadObject for validation
10081008
const auto& headResult = headObjectOutcome.GetResult();
1009-
// Capture any available checksum for validation (prioritize CRC32 as per SEP)
10101009
if (!headResult.GetChecksumCRC32().empty()) {
10111010
handle->SetChecksum(headResult.GetChecksumCRC32());
10121011
} else if (!headResult.GetChecksumCRC32C().empty()) {
@@ -1250,11 +1249,9 @@ namespace Aws
12501249
if (failedParts.size() == 0 && handle->GetBytesTransferred() == handle->GetBytesTotalSize())
12511250
{
12521251
outcome.GetResult().GetBody().flush();
1253-
1254-
// Validate full object checksum if available
1252+
12551253
bool checksumValid = true;
12561254
if (!handle->GetChecksum().empty()) {
1257-
// Combine part checksums to calculate full object checksum
12581255
Aws::String calculatedChecksum = CombinePartChecksums(handle);
12591256

12601257
if (!calculatedChecksum.empty() && calculatedChecksum != handle->GetChecksum()) {
@@ -1274,11 +1271,9 @@ namespace Aws
12741271
return;
12751272
}
12761273
}
1277-
1278-
// Rename temp file to final file if using temporary file pattern
1274+
12791275
if (!handle->GetTargetFilePath().empty() && checksumValid) {
12801276
if (handle->GetTargetFilePath().find(".s3tmp.") != Aws::String::npos) {
1281-
// This is a temp file, rename to final
12821277
Aws::String finalFile = handle->GetTargetFilePath();
12831278
size_t pos = finalFile.find(".s3tmp.");
12841279
if (pos != Aws::String::npos) {
@@ -1675,8 +1670,7 @@ namespace Aws
16751670
sortedParts.emplace_back(part.first, part.second->GetChecksum());
16761671
}
16771672
std::sort(sortedParts.begin(), sortedParts.end());
1678-
1679-
// For CRC32, combine checksums using XOR (simplified approach)
1673+
16801674
uint32_t combinedCrc = 0;
16811675
for (const auto& part : sortedParts) {
16821676
char* endPtr = nullptr;
@@ -1688,34 +1682,29 @@ namespace Aws
16881682
}
16891683
combinedCrc ^= partCrc;
16901684
}
1691-
1692-
// Convert back to hex string
1685+
16931686
std::stringstream ss;
16941687
ss << std::hex << combinedCrc;
16951688
return ss.str();
16961689
}
16971690

16981691
Aws::String TransferManager::GenerateTempFileName(const Aws::String& finalFileName) {
1699-
// Generate unique identifier (max 8 chars as per SEP)
17001692
Aws::String uuid = Aws::Utils::UUID::RandomUUID();
17011693
Aws::String uniqueId = uuid.length() > 8 ? uuid.substr(0, 8) : uuid;
17021694
return finalFileName + ".s3tmp." + uniqueId;
17031695
}
17041696

17051697
bool TransferManager::RenameTempFileToFinal(const Aws::String& tempFile, const Aws::String& finalFile) {
1706-
// Use atomic rename if supported by platform
17071698
if (std::rename(tempFile.c_str(), finalFile.c_str()) == 0) {
17081699
return true;
17091700
}
1710-
1711-
// Fallback strategy for platforms without atomic rename
1701+
17121702
if (Aws::FileSystem::RemoveFileIfExists(finalFile.c_str())) {
17131703
if (std::rename(tempFile.c_str(), finalFile.c_str()) == 0) {
17141704
return true;
17151705
}
17161706
}
1717-
1718-
// Clean up temp file on failure
1707+
17191708
Aws::FileSystem::RemoveFileIfExists(tempFile.c_str());
17201709
return false;
17211710
}

tests/aws-cpp-sdk-transfer-tests/TransferTests.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,24 +2342,21 @@ TEST_P(TransferTests, TransferManager_DownloadWithChecksumValidationIntegrationT
23422342

23432343
auto transferManager = TransferManager::Create(transferManagerConfig);
23442344

2345-
// Upload file with checksum enabled
23462345
auto uploadPtr = transferManager->UploadFile(testFilePath, GetTestBucketName(), RandomFileName,
23472346
"text/plain", Aws::Map<Aws::String, Aws::String>());
23482347

23492348
uploadPtr->WaitUntilFinished();
23502349
ASSERT_EQ(TransferStatus::COMPLETED, uploadPtr->GetStatus());
23512350
ASSERT_TRUE(WaitForObjectToPropagate(GetTestBucketName(), RandomFileName.c_str()));
23522351

2353-
// Download file - should validate checksum successfully
23542352
Aws::String downloadFilePath = MakeFilePath((RandomFileName + "Download").c_str());
23552353
auto downloadPtr = transferManager->DownloadFile(GetTestBucketName(), RandomFileName, downloadFilePath);
23562354

23572355
downloadPtr->WaitUntilFinished();
2358-
2359-
// Should complete successfully with valid checksum
2356+
23602357
ASSERT_EQ(TransferStatus::COMPLETED, downloadPtr->GetStatus());
23612358

2362-
// Verify the downloaded file exists by trying to open it
2359+
// Verify the downloaded file exists
23632360
std::ifstream file(downloadFilePath.c_str());
23642361
ASSERT_TRUE(file.good());
23652362
file.close();

0 commit comments

Comments
 (0)