1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-13 05:56:03 +01:00

libstore: Make uploads with filetransfer.cc consume a RestartableSource

Make uploads run in constant memory. Also change the callbacks to be
noexcept, since we really don't want to be unwinding the stack in the
curl thread. That will definitely corrupt that stack and make nix/curl
crash in very bad ways.
This commit is contained in:
Sergei Zimmerman 2025-10-29 01:29:09 +03:00 committed by John Ericson
parent b8d7f551e4
commit cf75079bd8
9 changed files with 87 additions and 42 deletions

View file

@ -20,8 +20,8 @@ public:
{
}
void
upsertFile(const std::string & path, Source & source, const std::string & mimeType, uint64_t sizeHint) override;
void upsertFile(
const std::string & path, RestartableSource & source, const std::string & mimeType, uint64_t sizeHint) override;
private:
ref<S3BinaryCacheStoreConfig> s3Config;
@ -67,7 +67,7 @@ private:
};
void S3BinaryCacheStore::upsertFile(
const std::string & path, Source & source, const std::string & mimeType, uint64_t sizeHint)
const std::string & path, RestartableSource & source, const std::string & mimeType, uint64_t sizeHint)
{
HttpBinaryCacheStore::upsertFile(path, source, mimeType, sizeHint);
}
@ -86,7 +86,8 @@ std::string S3BinaryCacheStore::createMultipartUpload(
req.uri = VerbatimURL(url);
req.method = HttpMethod::POST;
req.data = "";
StringSource payload{std::string_view("")};
req.data = {payload};
req.mimeType = mimeType;
if (contentEncoding) {
@ -116,7 +117,8 @@ S3BinaryCacheStore::uploadPart(std::string_view key, std::string_view uploadId,
url.query["partNumber"] = std::to_string(partNumber);
url.query["uploadId"] = uploadId;
req.uri = VerbatimURL(url);
req.data = std::move(data);
StringSource payload{data};
req.data = {payload};
req.mimeType = "application/octet-stream";
auto result = getFileTransfer()->enqueueFileTransfer(req).get();
@ -163,7 +165,8 @@ void S3BinaryCacheStore::completeMultipartUpload(
debug("S3 CompleteMultipartUpload XML (%d parts): %s", parts.size(), xml);
req.data = xml;
StringSource payload{xml};
req.data = {payload};
req.mimeType = "text/xml";
getFileTransfer()->enqueueFileTransfer(req).get();