Skip to content

Commit 90dfca3

Browse files
committed
Substitute NARs from the local NAR cache
1 parent 779d7a9 commit 90dfca3

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

src/libstore/binary-cache-store.cc

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,29 @@ void BinaryCacheStore::narFromPath(const StorePath & storePath, Sink & sink)
410410
{
411411
auto info = queryPathInfo(storePath).cast<const NarInfo>();
412412

413+
if (narCache) {
414+
if (auto nar = narCache->getNar(info->narHash)) {
415+
notice("substituted '%s' from local NAR cache", printStorePath(storePath));
416+
sink(*nar);
417+
stats.narRead++;
418+
stats.narReadBytes += nar->size();
419+
return;
420+
}
421+
}
422+
413423
LengthSink narSize;
414-
TeeSink tee{sink, narSize};
424+
TeeSink tee{narSize, sink};
425+
std::unique_ptr<Sink> narCacheSink;
426+
std::unique_ptr<Sink> tee2;
427+
Sink * sink2 = &tee;
428+
429+
if (narCache) {
430+
narCacheSink = sourceToSink([&](Source & source) { narCache->upsertNar(info->narHash, source); });
431+
tee2 = std::make_unique<TeeSink>(*narCacheSink, tee);
432+
sink2 = tee2.get();
433+
}
415434

416-
auto decompressor = makeDecompressionSink(info->compression, tee);
435+
auto decompressor = makeDecompressionSink(info->compression, *sink2);
417436

418437
try {
419438
getFile(info->url, *decompressor);
@@ -423,6 +442,7 @@ void BinaryCacheStore::narFromPath(const StorePath & storePath, Sink & sink)
423442

424443
decompressor->finish();
425444

445+
// FIXME: this is never reached
426446
stats.narRead++;
427447
// stats.narReadCompressedBytes += nar->size(); // FIXME
428448
stats.narReadBytes += narSize.length;

0 commit comments

Comments
 (0)