Skip to content

Commit

Permalink
fix: correct multipart XML CompleteMultipartUploadResult (#183)
Browse files Browse the repository at this point in the history
existing implementation was not parsing complete multipart
response properly.

Bonus: add support for new checksum fields
  • Loading branch information
harshavardhana authored Jan 5, 2025
1 parent 5a5533e commit 818d203
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
4 changes: 4 additions & 0 deletions include/miniocpp/response.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ struct CompleteMultipartUploadResponse : public Response {
std::string location;
std::string etag;
std::string version_id;
std::string checksumCRC32;
std::string checksumCRC32C;
std::string checksumSHA1;
std::string checksumSHA256;

CompleteMultipartUploadResponse() = default;

Expand Down
15 changes: 13 additions & 2 deletions src/response.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ CompleteMultipartUploadResponse CompleteMultipartUploadResponse::ParseXML(
if (!result) {
return error::make<CompleteMultipartUploadResponse>("unable to parse XML");
}
auto root = xdoc.select_node("/CompleteMultipartUploadOutput");

auto root = xdoc.select_node("/CompleteMultipartUploadResult");
pugi::xpath_node text;

text = root.node().select_node("Bucket/text()");
Expand All @@ -139,6 +138,18 @@ CompleteMultipartUploadResponse CompleteMultipartUploadResponse::ParseXML(
text = root.node().select_node("ETag/text()");
resp.etag = utils::Trim(text.node().value(), '"');

text = root.node().select_node("ChecksumCRC32/text()");
resp.checksumCRC32 = text.node().value();

text = root.node().select_node("ChecksumCRC32/text()");
resp.checksumCRC32C = text.node().value();

text = root.node().select_node("ChecksumSHA1/text()");
resp.checksumSHA1 = text.node().value();

text = root.node().select_node("ChecksumSHA256/text()");
resp.checksumSHA256 = text.node().value();

resp.version_id = version_id;

return resp;
Expand Down
11 changes: 6 additions & 5 deletions tests/tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,7 @@ class Tests {
std::string object_name = RandObjectName();
std::string data = "PutObject()";
std::stringstream ss(data);
minio::s3::PutObjectArgs args(
ss, static_cast<long>(data.length()),
0); // PWTODO: PutObjectArgs should accept size_t instead of long
minio::s3::PutObjectArgs args(ss, data.length(), 0);
args.bucket = bucket_name_;
args.object = object_name;
minio::s3::PutObjectResponse resp = client_.PutObject(args);
Expand All @@ -475,16 +473,19 @@ class Tests {

{
std::string object_name = RandObjectName();
size_t size = 13930573;
size_t size = 67108865; // (64MiB + 1) bytes
RandCharStream stream(size);
minio::s3::PutObjectArgs args(stream, static_cast<long>(size), 0);
minio::s3::PutObjectArgs args(stream, size, 0);
args.bucket = bucket_name_;
args.object = object_name;
minio::s3::PutObjectResponse resp = client_.PutObject(args);
if (!resp) {
throw std::runtime_error("<Multipart> PutObject(): " +
resp.Error().String());
}
if (resp.etag == "") {
throw std::runtime_error("<Multipart> PutObject(): etag is missing");
}
RemoveObject(bucket_name_, object_name);
}
}
Expand Down

0 comments on commit 818d203

Please sign in to comment.