1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 03:56:01 +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

@ -135,19 +135,28 @@ bool HttpBinaryCacheStore::fileExists(const std::string & path)
}
void HttpBinaryCacheStore::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)
{
auto req = makeRequest(path);
req.method = HttpMethod::PUT;
auto data = source.drain();
auto compressionMethod = getCompressionMethod(path);
std::string data;
std::optional<StringSource> stringSource{};
if (compressionMethod) {
data = compress(*compressionMethod, data);
StringSink sink{};
auto compressionSink = makeCompressionSink(*compressionMethod, sink);
source.drainInto(*compressionSink);
compressionSink->finish();
data = std::move(sink.s);
req.headers.emplace_back("Content-Encoding", *compressionMethod);
stringSource = StringSource{data};
req.data = {*stringSource};
} else {
req.data = {sizeHint, source};
}
req.data = std::move(data);
req.mimeType = mimeType;
try {