From 456b9175353b5587a8fbaa325c888971e094bef4 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sun, 12 Oct 2025 22:49:04 -0400 Subject: [PATCH] `Store::addToStore` bail out on no-op earlier in many cases `BinaryCacheStore` and `LocalStore` already had this optimization. Now, all the implementations do. --- src/libstore/binary-cache-store.cc | 4 ++-- src/libstore/dummy-store.cc | 4 ++++ src/libstore/legacy-ssh-store.cc | 6 ++++++ src/libstore/remote-store.cc | 6 ++++++ src/libstore/store-api.cc | 10 ++++++++++ 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index badfb4b14..951d1a027 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -296,8 +296,8 @@ void BinaryCacheStore::addToStore( const ValidPathInfo & info, Source & narSource, RepairFlag repair, CheckSigsFlag checkSigs) { if (!repair && isValidPath(info.path)) { - // FIXME: copyNAR -> null sink - narSource.drain(); + NullFileSystemObjectSink s; + parseDump(s, narSource); return; } diff --git a/src/libstore/dummy-store.cc b/src/libstore/dummy-store.cc index b25f961f3..d21d54b7c 100644 --- a/src/libstore/dummy-store.cc +++ b/src/libstore/dummy-store.cc @@ -160,6 +160,10 @@ struct DummyStoreImpl : DummyStore void addToStore(const ValidPathInfo & info, const SourcePath & path, RepairFlag repair, CheckSigsFlag checkSigs) override { + if (!repair && isValidPath(info.path)) { + return; + } + if (config->readOnly) unsupported("addToStore"); diff --git a/src/libstore/legacy-ssh-store.cc b/src/libstore/legacy-ssh-store.cc index 3b466c9bb..f7f5b9766 100644 --- a/src/libstore/legacy-ssh-store.cc +++ b/src/libstore/legacy-ssh-store.cc @@ -145,6 +145,12 @@ void LegacySSHStore::queryPathInfoUncached( void LegacySSHStore::addToStore(const ValidPathInfo & info, Source & source, RepairFlag repair, CheckSigsFlag checkSigs) { + if (!repair && isValidPath(info.path)) { + NullFileSystemObjectSink s; + parseDump(s, source); + return; + } + debug("adding path '%s' to remote host '%s'", printStorePath(info.path), config->authority.host); auto conn(connections->get()); diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index a6994f844..63dd5d06c 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -424,6 +424,12 @@ StorePath RemoteStore::addToStoreFromDump( void RemoteStore::addToStore(const ValidPathInfo & info, Source & source, RepairFlag repair, CheckSigsFlag checkSigs) { + if (!repair && isValidPath(info.path)) { + NullFileSystemObjectSink s; + parseDump(s, source); + return; + } + auto conn(getConnection()); conn->to << WorkerProto::Op::AddToStoreNar << printStorePath(info.path) diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 8bf493a19..fbc11edb2 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -86,6 +86,12 @@ StorePath Store::followLinksToStorePath(std::string_view path) const void Store::addToStore(const ValidPathInfo & info, Source & narSource, RepairFlag repair, CheckSigsFlag checkSigs) { + if (!repair && isValidPath(info.path)) { + NullFileSystemObjectSink s; + parseDump(s, narSource); + return; + } + auto temp = make_ref(); MemorySink tempSink{*temp}; parseDump(tempSink, narSource); @@ -94,6 +100,10 @@ void Store::addToStore(const ValidPathInfo & info, Source & narSource, RepairFla void Store::addToStore(const ValidPathInfo & info, const SourcePath & path, RepairFlag repair, CheckSigsFlag checkSigs) { + if (!repair && isValidPath(info.path)) { + return; + } + auto sink = sourceToSink([&](Source & source) { addToStore(info, source, repair, checkSigs); }); dumpPath(path, *sink, FileSerialisationMethod::NixArchive); }