in src/aws-cpp-sdk-transfer/source/transfer/TransferManager.cpp [1084:1161]
void TransferManager::HandleGetObjectResponse(const Aws::S3::S3Client* client,
const Aws::S3::Model::GetObjectRequest& request,
const Aws::S3::Model::GetObjectOutcome& outcome,
const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context)
{
AWS_UNREFERENCED_PARAM(client);
AWS_UNREFERENCED_PARAM(request);
std::shared_ptr<TransferHandleAsyncContext> transferContext =
std::const_pointer_cast<TransferHandleAsyncContext>(std::static_pointer_cast<const TransferHandleAsyncContext>(context));
const auto& handle = transferContext->handle;
const auto& partState = transferContext->partState;
if (!outcome.IsSuccess())
{
AWS_LOGSTREAM_ERROR(CLASS_TAG, "Transfer handle [" << handle->GetId()
<< "] Failed to download object in Bucket: ["
<< handle->GetBucketName() << "] with Key: [" << handle->GetKey()
<< "] " << outcome.GetError());
handle->ChangePartToFailed(partState);
handle->SetError(outcome.GetError());
TriggerErrorCallback(handle, outcome.GetError());
}
else
{
if(handle->ShouldContinue())
{
Aws::IOStream* bufferStream = partState->GetDownloadPartStream();
assert(bufferStream);
Aws::String errMsg{handle->WritePartToDownloadStream(bufferStream, partState->GetRangeBegin())};
if (errMsg.empty()) {
handle->ChangePartToCompleted(partState, outcome.GetResult().GetETag());
} else {
Aws::Client::AWSError<Aws::S3::S3Errors> error(Aws::S3::S3Errors::INTERNAL_FAILURE,
"InternalFailure", errMsg, false);
AWS_LOGSTREAM_ERROR(CLASS_TAG, "Transfer handle [" << handle->GetId()
<< "] Failed to download object in Bucket: ["
<< handle->GetBucketName() << "] with Key: [" << handle->GetKey()
<< "] " << errMsg);
handle->ChangePartToFailed(partState);
handle->SetError(error);
TriggerErrorCallback(handle, error);
}
}
else
{
handle->ChangePartToFailed(partState);
}
}
// buffer cleanup
if(partState->GetDownloadBuffer())
{
m_bufferManager.Release(partState->GetDownloadBuffer());
partState->SetDownloadBuffer(nullptr);
}
TriggerTransferStatusUpdatedCallback(handle);
PartStateMap pendingParts, queuedParts, failedParts, completedParts;
handle->GetAllPartsTransactional(queuedParts, pendingParts, failedParts, completedParts);
if (pendingParts.size() == 0 && queuedParts.size() == 0)
{
if (failedParts.size() == 0 && handle->GetBytesTransferred() == handle->GetBytesTotalSize())
{
outcome.GetResult().GetBody().flush();
handle->UpdateStatus(TransferStatus::COMPLETED);
}
else
{
handle->UpdateStatus(DetermineIfFailedOrCanceled(*handle));
}
TriggerTransferStatusUpdatedCallback(handle);
}
partState->SetDownloadPartStream(nullptr);
}