Skip to content

Commit 7ba8443

Browse files
committed
BinaryCacheStore::narFromPath(): Fix unreachable code
When this function is called as a coroutine (e.g. when it's called by `copyStorePath()`), the code after `decompressor->finish()` is never reached because the coroutine is destroyed when the caller reaches the end of the NAR. So put that code in a `LambdaSink` destructor.
1 parent d7b6afe commit 7ba8443

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/libstore/binary-cache-store.cc

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,20 @@ void BinaryCacheStore::narFromPath(const StorePath & storePath, Sink & sink)
418418
{
419419
auto info = queryPathInfo(storePath).cast<const NarInfo>();
420420

421-
LengthSink narSize;
422-
TeeSink tee{sink, narSize};
421+
uint64_t narSize = 0;
423422

424-
auto decompressor = makeDecompressionSink(info->compression, tee);
423+
LambdaSink uncompressedSink{
424+
[&](std::string_view data) {
425+
narSize += data.size();
426+
sink(data);
427+
},
428+
[&]() {
429+
stats.narRead++;
430+
// stats.narReadCompressedBytes += nar->size(); // FIXME
431+
stats.narReadBytes += narSize;
432+
}};
433+
434+
auto decompressor = makeDecompressionSink(info->compression, uncompressedSink);
425435

426436
try {
427437
getFile(info->url, *decompressor);
@@ -431,9 +441,7 @@ void BinaryCacheStore::narFromPath(const StorePath & storePath, Sink & sink)
431441

432442
decompressor->finish();
433443

434-
stats.narRead++;
435-
// stats.narReadCompressedBytes += nar->size(); // FIXME
436-
stats.narReadBytes += narSize.length;
444+
// Note: don't do anything here because it's never reached if we're called as a coroutine.
437445
}
438446

439447
void BinaryCacheStore::queryPathInfoUncached(

0 commit comments

Comments
 (0)