mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 12:06:01 +01:00
Add a new addToStore variant
This is nicer for the dummy store to implement, and some callers to use.
This commit is contained in:
parent
f77094715f
commit
f8095b793d
3 changed files with 42 additions and 12 deletions
|
|
@ -157,7 +157,8 @@ 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 (config->readOnly)
|
||||
unsupported("addToStore");
|
||||
|
|
@ -168,19 +169,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(
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,20 @@ 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue