mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 11:36:03 +01:00
Merge pull request #14391 from lovesegfault/nix-s3-complete-multipart
feat(libstore/s3-binary-cache-store): implement `completeMultipartUpload()`
This commit is contained in:
commit
e3c41407f9
1 changed files with 42 additions and 0 deletions
|
|
@ -5,6 +5,7 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <span>
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
|
@ -46,6 +47,19 @@ private:
|
||||||
*/
|
*/
|
||||||
std::string uploadPart(std::string_view key, std::string_view uploadId, uint64_t partNumber, std::string data);
|
std::string uploadPart(std::string_view key, std::string_view uploadId, uint64_t partNumber, std::string data);
|
||||||
|
|
||||||
|
struct UploadedPart
|
||||||
|
{
|
||||||
|
uint64_t partNumber;
|
||||||
|
std::string etag;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Completes a multipart upload by combining all uploaded parts.
|
||||||
|
* @see
|
||||||
|
* https://docs.aws.amazon.com/AmazonS3/latest/API/API_CompleteMultipartUpload.html#API_CompleteMultipartUpload_RequestSyntax
|
||||||
|
*/
|
||||||
|
void completeMultipartUpload(std::string_view key, std::string_view uploadId, std::span<const UploadedPart> parts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abort a multipart upload
|
* Abort a multipart upload
|
||||||
*
|
*
|
||||||
|
|
@ -133,6 +147,34 @@ void S3BinaryCacheStore::abortMultipartUpload(std::string_view key, std::string_
|
||||||
getFileTransfer()->enqueueFileTransfer(req).get();
|
getFileTransfer()->enqueueFileTransfer(req).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void S3BinaryCacheStore::completeMultipartUpload(
|
||||||
|
std::string_view key, std::string_view uploadId, std::span<const UploadedPart> parts)
|
||||||
|
{
|
||||||
|
auto req = makeRequest(key);
|
||||||
|
req.setupForS3();
|
||||||
|
|
||||||
|
auto url = req.uri.parsed();
|
||||||
|
url.query["uploadId"] = uploadId;
|
||||||
|
req.uri = VerbatimURL(url);
|
||||||
|
req.method = HttpMethod::POST;
|
||||||
|
|
||||||
|
std::string xml = "<CompleteMultipartUpload>";
|
||||||
|
for (const auto & part : parts) {
|
||||||
|
xml += "<Part>";
|
||||||
|
xml += "<PartNumber>" + std::to_string(part.partNumber) + "</PartNumber>";
|
||||||
|
xml += "<ETag>" + part.etag + "</ETag>";
|
||||||
|
xml += "</Part>";
|
||||||
|
}
|
||||||
|
xml += "</CompleteMultipartUpload>";
|
||||||
|
|
||||||
|
debug("S3 CompleteMultipartUpload XML (%d parts): %s", parts.size(), xml);
|
||||||
|
|
||||||
|
req.data = xml;
|
||||||
|
req.mimeType = "text/xml";
|
||||||
|
|
||||||
|
getFileTransfer()->enqueueFileTransfer(req).get();
|
||||||
|
}
|
||||||
|
|
||||||
StringSet S3BinaryCacheStoreConfig::uriSchemes()
|
StringSet S3BinaryCacheStoreConfig::uriSchemes()
|
||||||
{
|
{
|
||||||
return {"s3"};
|
return {"s3"};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue