@@ -420,19 +420,26 @@ void BinaryCacheStore::narFromPath(const StorePath & storePath, Sink & sink)
420420 }
421421 }
422422
423- LengthSink narSize;
424- TeeSink tee{narSize, sink};
425423 std::unique_ptr<Sink> narCacheSink;
426- std::unique_ptr<Sink> tee2;
427- Sink * sink2 = &tee;
428-
429- if (narCache) {
424+ if (narCache)
430425 narCacheSink = sourceToSink ([&](Source & source) { narCache->upsertNar (info->narHash , source); });
431- tee2 = std::make_unique<TeeSink>(*narCacheSink, tee);
432- sink2 = tee2.get ();
433- }
434426
435- auto decompressor = makeDecompressionSink (info->compression , *sink2);
427+ uint64_t narSize = 0 ;
428+
429+ LambdaSink uncompressedSink{
430+ [&](std::string_view data) {
431+ narSize += data.size ();
432+ if (narCacheSink)
433+ (*narCacheSink)(data);
434+ sink (data);
435+ },
436+ [&]() {
437+ stats.narRead ++;
438+ // stats.narReadCompressedBytes += nar->size(); // FIXME
439+ stats.narReadBytes += narSize;
440+ }};
441+
442+ auto decompressor = makeDecompressionSink (info->compression , uncompressedSink);
436443
437444 try {
438445 getFile (info->url , *decompressor);
@@ -442,10 +449,7 @@ void BinaryCacheStore::narFromPath(const StorePath & storePath, Sink & sink)
442449
443450 decompressor->finish ();
444451
445- // FIXME: this is never reached
446- stats.narRead ++;
447- // stats.narReadCompressedBytes += nar->size(); // FIXME
448- stats.narReadBytes += narSize.length ;
452+ // Note: don't do anything here because it's never reached if we're called as a coroutine.
449453}
450454
451455void BinaryCacheStore::queryPathInfoUncached (
0 commit comments