Skip to content

Commit 7af986f

Browse files
authored
Fetching ETag directly from metadata (#157)
Added support for fetching ETag directly from metadata when doing upload with Aws Transfer Only set Etag to handle's metadata when part is the last part
1 parent 499432c commit 7af986f

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace Aws
5454
{
5555
public:
5656
PartState();
57-
PartState(int partId, size_t bestProgressInBytes, size_t sizeInBytes);
57+
PartState(int partId, size_t bestProgressInBytes, size_t sizeInBytes, bool lastPart = false);
5858

5959
int GetPartId() const { return m_partId; }
6060

@@ -80,6 +80,9 @@ namespace Aws
8080
void SetRangeBegin(size_t rangeBegin) { m_rangeBegin = rangeBegin; }
8181
size_t GetRangeBegin() const { return m_rangeBegin; }
8282

83+
bool IsLastPart() { return m_lastPart; }
84+
void SetLastPart() { m_lastPart = true; }
85+
8386
private:
8487

8588
int m_partId;
@@ -92,6 +95,7 @@ namespace Aws
9295

9396
std::atomic<Aws::IOStream *> m_downloadPartStream;
9497
std::atomic<Aws::Utils::Array<unsigned char> *> m_downloadBuffer;
98+
bool m_lastPart;
9599
};
96100

97101
using PartPointer = std::shared_ptr< PartState >;
@@ -298,6 +302,11 @@ namespace Aws
298302
*/
299303
inline void SetMetadata(const Aws::Map<Aws::String, Aws::String>& value) { m_metadata = value; }
300304

305+
/**
306+
* Add a new entry to or update an existed entry of m_metadata, useful when users want to get ETag directly from metadata.
307+
*/
308+
inline void AddMetadataEntry(const Aws::String& key, const Aws::String& value) { m_metadata[key] = value; }
309+
301310
/**
302311
* The current status of the operation
303312
*/

aws-cpp-sdk-transfer/source/transfer/TransferHandle.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,20 @@ namespace Aws
3030
m_sizeInBytes(0),
3131
m_rangeBegin(0),
3232
m_downloadPartStream(nullptr),
33-
m_downloadBuffer(nullptr)
33+
m_downloadBuffer(nullptr),
34+
m_lastPart(false)
3435
{}
3536

36-
PartState::PartState(int partId, size_t bestProgressInBytes, size_t sizeInBytes) :
37+
PartState::PartState(int partId, size_t bestProgressInBytes, size_t sizeInBytes, bool lastPart) :
3738
m_partId(partId),
3839
m_eTag(""),
3940
m_currentProgressInBytes(0),
4041
m_bestProgressInBytes(bestProgressInBytes),
4142
m_sizeInBytes(sizeInBytes),
4243
m_rangeBegin(0),
4344
m_downloadPartStream(nullptr),
44-
m_downloadBuffer(nullptr)
45+
m_downloadBuffer(nullptr),
46+
m_lastPart(lastPart)
4547
{}
4648

4749

@@ -128,6 +130,10 @@ namespace Aws
128130
}
129131

130132
partState->SetETag(eTag);
133+
if (partState->IsLastPart())
134+
{
135+
AddMetadataEntry("ETag", eTag);
136+
}
131137
m_completedParts[partState->GetPartId()] = partState;
132138
}
133139

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ namespace Aws
243243
for (uint64_t i = 0; i < partCount; ++i)
244244
{
245245
uint64_t partSize = std::min(totalSize - i * m_transferConfig.bufferSize, m_transferConfig.bufferSize);
246-
handle->AddQueuedPart(Aws::MakeShared<PartState>(CLASS_TAG, static_cast<int>(i + 1), 0, static_cast<size_t>(partSize)));
246+
bool lastPart = (i == partCount - 1) ? true : false;
247+
handle->AddQueuedPart(Aws::MakeShared<PartState>(CLASS_TAG, static_cast<int>(i + 1), 0, static_cast<size_t>(partSize), lastPart));
247248
}
248249
}
249250
else
@@ -339,7 +340,7 @@ namespace Aws
339340

340341
void TransferManager::DoSinglePartUpload(Aws::IOStream* streamToPut, const std::shared_ptr<TransferHandle>& handle)
341342
{
342-
auto partState = Aws::MakeShared<PartState>(CLASS_TAG, 1, 0, static_cast<size_t>(handle->GetBytesTotalSize()));
343+
auto partState = Aws::MakeShared<PartState>(CLASS_TAG, 1, 0, static_cast<size_t>(handle->GetBytesTotalSize()), true);
343344

344345
handle->UpdateStatus(TransferStatus::IN_PROGRESS);
345346
handle->SetIsMultipart(false);
@@ -609,7 +610,8 @@ namespace Aws
609610
for(std::size_t i = 0; i < partCount; ++i)
610611
{
611612
std::size_t partSize = (i + 1 < partCount ) ? bufferSize : (downloadSize - bufferSize * (partCount - 1));
612-
auto partState = Aws::MakeShared<PartState>(CLASS_TAG, static_cast<int>(i + 1), 0, partSize);
613+
bool lastPart = (i == partCount - 1) ? true : false;
614+
auto partState = Aws::MakeShared<PartState>(CLASS_TAG, static_cast<int>(i + 1), 0, partSize, lastPart);
613615
partState->SetRangeBegin(i * bufferSize);
614616
handle->AddQueuedPart(partState);
615617
}

0 commit comments

Comments
 (0)