mirror of
https://github.com/NixOS/nix.git
synced 2025-11-17 16:02:43 +01:00
Move exportPaths() / importPaths() out of the Store class
This commit is contained in:
parent
5e46df973f
commit
fe5b669534
6 changed files with 57 additions and 49 deletions
|
|
@ -1,3 +1,4 @@
|
|||
#include "nix/store/export-import.hh"
|
||||
#include "nix/util/serialise.hh"
|
||||
#include "nix/store/store-api.hh"
|
||||
#include "nix/util/archive.hh"
|
||||
|
|
@ -8,27 +9,14 @@
|
|||
|
||||
namespace nix {
|
||||
|
||||
void Store::exportPaths(const StorePathSet & paths, Sink & sink)
|
||||
static void exportPath(Store & store, const StorePath & path, Sink & sink)
|
||||
{
|
||||
auto sorted = topoSortPaths(paths);
|
||||
std::reverse(sorted.begin(), sorted.end());
|
||||
|
||||
for (auto & path : sorted) {
|
||||
sink << 1;
|
||||
exportPath(path, sink);
|
||||
}
|
||||
|
||||
sink << 0;
|
||||
}
|
||||
|
||||
void Store::exportPath(const StorePath & path, Sink & sink)
|
||||
{
|
||||
auto info = queryPathInfo(path);
|
||||
auto info = store.queryPathInfo(path);
|
||||
|
||||
HashSink hashSink(HashAlgorithm::SHA256);
|
||||
TeeSink teeSink(sink, hashSink);
|
||||
|
||||
narFromPath(path, teeSink);
|
||||
store.narFromPath(path, teeSink);
|
||||
|
||||
/* Refuse to export paths that have changed. This prevents
|
||||
filesystem corruption from spreading to other machines.
|
||||
|
|
@ -37,16 +25,29 @@ void Store::exportPath(const StorePath & path, Sink & sink)
|
|||
if (hash != info->narHash && info->narHash != Hash(info->narHash.algo))
|
||||
throw Error(
|
||||
"hash of path '%s' has changed from '%s' to '%s'!",
|
||||
printStorePath(path),
|
||||
store.printStorePath(path),
|
||||
info->narHash.to_string(HashFormat::Nix32, true),
|
||||
hash.to_string(HashFormat::Nix32, true));
|
||||
|
||||
teeSink << exportMagic << printStorePath(path);
|
||||
CommonProto::write(*this, CommonProto::WriteConn{.to = teeSink}, info->references);
|
||||
teeSink << (info->deriver ? printStorePath(*info->deriver) : "") << 0;
|
||||
teeSink << exportMagic << store.printStorePath(path);
|
||||
CommonProto::write(store, CommonProto::WriteConn{.to = teeSink}, info->references);
|
||||
teeSink << (info->deriver ? store.printStorePath(*info->deriver) : "") << 0;
|
||||
}
|
||||
|
||||
StorePaths Store::importPaths(Source & source, CheckSigsFlag checkSigs)
|
||||
void exportPaths(Store & store, const StorePathSet & paths, Sink & sink)
|
||||
{
|
||||
auto sorted = store.topoSortPaths(paths);
|
||||
std::reverse(sorted.begin(), sorted.end());
|
||||
|
||||
for (auto & path : sorted) {
|
||||
sink << 1;
|
||||
exportPath(store, path, sink);
|
||||
}
|
||||
|
||||
sink << 0;
|
||||
}
|
||||
|
||||
StorePaths importPaths(Store & store, Source & source, CheckSigsFlag checkSigs)
|
||||
{
|
||||
StorePaths res;
|
||||
while (true) {
|
||||
|
|
@ -66,17 +67,17 @@ StorePaths Store::importPaths(Source & source, CheckSigsFlag checkSigs)
|
|||
if (magic != exportMagic)
|
||||
throw Error("Nix archive cannot be imported; wrong format");
|
||||
|
||||
auto path = parseStorePath(readString(source));
|
||||
auto path = store.parseStorePath(readString(source));
|
||||
|
||||
// Activity act(*logger, lvlInfo, "importing path '%s'", info.path);
|
||||
|
||||
auto references = CommonProto::Serialise<StorePathSet>::read(*this, CommonProto::ReadConn{.from = source});
|
||||
auto references = CommonProto::Serialise<StorePathSet>::read(store, CommonProto::ReadConn{.from = source});
|
||||
auto deriver = readString(source);
|
||||
auto narHash = hashString(HashAlgorithm::SHA256, saved.s);
|
||||
|
||||
ValidPathInfo info{path, narHash};
|
||||
if (deriver != "")
|
||||
info.deriver = parseStorePath(deriver);
|
||||
info.deriver = store.parseStorePath(deriver);
|
||||
info.references = references;
|
||||
info.narSize = saved.s.size();
|
||||
|
||||
|
|
@ -86,7 +87,7 @@ StorePaths Store::importPaths(Source & source, CheckSigsFlag checkSigs)
|
|||
|
||||
// Can't use underlying source, which would have been exhausted
|
||||
auto source = StringSource(saved.s);
|
||||
addToStore(info, source, NoRepair, checkSigs);
|
||||
store.addToStore(info, source, NoRepair, checkSigs);
|
||||
|
||||
res.push_back(info.path);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue