Skip to content

Commit 2e262c6

Browse files
authored
Merge pull request #14643 from NixOS/binary-cache-nar-from-path
BinaryCacheStore::narFromPath(): Fix unreachable code
2 parents 15b222b + 7ba8443 commit 2e262c6

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
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(

src/libutil/include/nix/util/serialise.hh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,18 +447,27 @@ struct LengthSource : Source
447447
*/
448448
struct LambdaSink : Sink
449449
{
450-
typedef std::function<void(std::string_view data)> lambda_t;
450+
typedef std::function<void(std::string_view data)> data_t;
451+
typedef std::function<void()> cleanup_t;
451452

452-
lambda_t lambda;
453+
data_t dataFun;
454+
cleanup_t cleanupFun;
453455

454-
LambdaSink(const lambda_t & lambda)
455-
: lambda(lambda)
456+
LambdaSink(
457+
const data_t & dataFun, const cleanup_t & cleanupFun = []() {})
458+
: dataFun(dataFun)
459+
, cleanupFun(cleanupFun)
460+
{
461+
}
462+
463+
~LambdaSink()
456464
{
465+
cleanupFun();
457466
}
458467

459468
void operator()(std::string_view data) override
460469
{
461-
lambda(data);
470+
dataFun(data);
462471
}
463472
};
464473

0 commit comments

Comments
 (0)