1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 04:21:16 +02:00

Make 'nix copy' to s3:// binary caches run in constant memory

This commit is contained in:
Eelco Dolstra 2020-07-13 20:07:19 +02:00
parent 493961b689
commit 7c2fef0a81
6 changed files with 57 additions and 27 deletions

View file

@ -15,6 +15,7 @@
#include <chrono>
#include <future>
#include <regex>
#include <fstream>
#include <nlohmann/json.hpp>
@ -58,11 +59,10 @@ void BinaryCacheStore::init()
}
void BinaryCacheStore::upsertFile(const std::string & path,
const std::string & data,
std::string && data,
const std::string & mimeType)
{
StringSource source(data);
upsertFile(path, source, mimeType);
upsertFile(path, std::make_shared<std::stringstream>(std::move(data)), mimeType);
}
void BinaryCacheStore::getFile(const std::string & path,
@ -279,8 +279,9 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, Source & narSource
/* Atomically write the NAR file. */
if (repair || !fileExists(narInfo->url)) {
stats.narWrite++;
FileSource source(fnTemp);
upsertFile(narInfo->url, source, "application/x-nix-nar");
upsertFile(narInfo->url,
std::make_shared<std::fstream>(fnTemp, std::ios_base::in),
"application/x-nix-nar");
} else
stats.narWriteAverted++;