diff --git a/src/libstore/dummy-store.cc b/src/libstore/dummy-store.cc index 1eb51fe3e..b25f961f3 100644 --- a/src/libstore/dummy-store.cc +++ b/src/libstore/dummy-store.cc @@ -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(); - MemorySink tempSink{*temp}; - parseDump(tempSink, source); - auto path = info.path; + auto accessor = make_ref(); + { + MemorySink tempSink{*accessor}; + copyRecursive(*path.accessor, path.path, tempSink, CanonPath::root); + } - auto accessor = make_ref(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( diff --git a/src/libstore/include/nix/store/store-api.hh b/src/libstore/include/nix/store/store-api.hh index 1131ec975..9a7d18899 100644 --- a/src/libstore/include/nix/store/store-api.hh +++ b/src/libstore/include/nix/store/store-api.hh @@ -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 diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 4ce6b15fa..8bf493a19 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -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(); + 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,