Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libstore/binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
23 changes: 14 additions & 9 deletions src/libstore/dummy-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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(
Expand Down
19 changes: 17 additions & 2 deletions src/libstore/include/nix/store/store-api.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/libstore/legacy-ssh-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
6 changes: 6 additions & 0 deletions src/libstore/remote-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 25 additions & 1 deletion src/libstore/store-api.cc
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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,
Expand Down
Loading