From d6f1e2de21b090ada8f658751ec1c528f13316bc Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 23 Oct 2025 21:17:09 +0200 Subject: [PATCH] Merge pull request #14323 from NixOS/skip-nar-parse addToStore(): Don't parse the NAR * StringSource: Implement skip() This is slightly faster than doing a read() into a buffer just to discard the data. * LocalStore::addToStore(): Skip unnecessary NARs rather than parsing them Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- src/libstore/local-store.cc | 6 ++---- src/libutil/include/nix/util/serialise.hh | 2 ++ src/libutil/serialise.cc | 10 ++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 59d5cc24f..3f108f97e 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -1048,15 +1048,13 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source, RepairF /* In case we are not interested in reading the NAR: discard it. */ bool narRead = false; Finally cleanup = [&]() { - if (!narRead) { - NullFileSystemObjectSink sink; + if (!narRead) try { - parseDump(sink, source); + source.skip(info.narSize); } catch (...) { // TODO: should Interrupted be handled here? ignoreExceptionInDestructor(); } - } }; addTempRoot(info.path); diff --git a/src/libutil/include/nix/util/serialise.hh b/src/libutil/include/nix/util/serialise.hh index 8799e128f..d6845a494 100644 --- a/src/libutil/include/nix/util/serialise.hh +++ b/src/libutil/include/nix/util/serialise.hh @@ -255,6 +255,8 @@ struct StringSource : Source } size_t read(char * data, size_t len) override; + + void skip(size_t len) override; }; /** diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc index 47a00c8d6..ba153625e 100644 --- a/src/libutil/serialise.cc +++ b/src/libutil/serialise.cc @@ -242,6 +242,16 @@ size_t StringSource::read(char * data, size_t len) return n; } +void StringSource::skip(size_t len) +{ + const size_t remain = s.size() - pos; + if (len > remain) { + pos = s.size(); + throw EndOfFile("end of string reached"); + } + pos += len; +} + std::unique_ptr sourceToSink(std::function fun) { struct SourceToSink : FinishSink