Compare commits

...

2 Commits

Author SHA1 Message Date
John Ericson
456b917535 Store::addToStore bail out on no-op earlier in many cases
`BinaryCacheStore` and `LocalStore` already had this optimization. Now,
all the implementations do.
2025-10-12 22:49:04 -04:00
John Ericson
f8095b793d Add a new addToStore variant
This is nicer for the dummy store to implement, and some callers to use.
2025-10-12 22:39:23 -04:00
6 changed files with 70 additions and 14 deletions

View File

@@ -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;
}

View File

@@ -157,8 +157,13 @@ struct DummyStoreImpl : DummyStore
unsupported("queryPathFromHashPart");
}
void addToStore(const ValidPathInfo & info, Source & source, RepairFlag repair, CheckSigsFlag checkSigs) override
void
addToStore(const ValidPathInfo & info, const SourcePath & path, RepairFlag repair, CheckSigsFlag checkSigs) override
{
if (!repair && isValidPath(info.path)) {
return;
}
if (config->readOnly)
unsupported("addToStore");
@@ -168,19 +173,19 @@ struct DummyStoreImpl : DummyStore
if (checkSigs)
throw Error("checking signatures is not supported for '%s' store", config->getHumanReadableURI());
auto temp = make_ref<MemorySourceAccessor>();
MemorySink tempSink{*temp};
parseDump(tempSink, source);
auto path = info.path;
auto accessor = make_ref<MemorySourceAccessor>();
{
MemorySink tempSink{*accessor};
copyRecursive(*path.accessor, path.path, tempSink, CanonPath::root);
}
auto accessor = make_ref<MemorySourceAccessor>(std::move(*temp));
contents.insert(
{path,
{info.path,
PathInfoAndContents{
std::move(info),
info,
accessor,
}});
wholeStoreView->addObject(path.to_string(), accessor);
wholeStoreView->addObject(info.path.to_string(), accessor);
}
StorePath addToStoreFromDump(

View File

@@ -511,13 +511,28 @@ public:
virtual void querySubstitutablePathInfos(const StorePathCAMap & paths, SubstitutablePathInfos & infos);
/**
* Import a path into the store.
* Import a path into the store, via NAR stream.
*
* One of these two must be overridden, as the defaults will
* infinitely mutually recur.
*/
virtual void addToStore(
const ValidPathInfo & info,
Source & narSource,
RepairFlag repair = NoRepair,
CheckSigsFlag checkSigs = CheckSigs) = 0;
CheckSigsFlag checkSigs = CheckSigs);
/**
* Import a path into the store, via arbitrary `SourcePath`.
*
* One of these two must be overridden, as the defaults will
* infinitely mutually recur.
*/
virtual void addToStore(
const ValidPathInfo & info,
const SourcePath & path,
RepairFlag repair = NoRepair,
CheckSigsFlag checkSigs = CheckSigs);
/**
* A list of paths infos along with a source providing the content

View File

@@ -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());

View File

@@ -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)

View File

@@ -1,6 +1,6 @@
#include "nix/util/logging.hh"
#include "nix/util/signature/local-keys.hh"
#include "nix/util/source-accessor.hh"
#include "nix/util/memory-source-accessor.hh"
#include "nix/store/globals.hh"
#include "nix/store/derived-path.hh"
#include "nix/store/realisation.hh"
@@ -84,6 +84,30 @@ StorePath Store::followLinksToStorePath(std::string_view path) const
return toStorePath(followLinksToStore(path)).first;
}
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<MemorySourceAccessor>();
MemorySink tempSink{*temp};
parseDump(tempSink, narSource);
addToStore(info, {temp}, repair, checkSigs);
}
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);
}
StorePath Store::addToStore(
std::string_view name,
const SourcePath & path,