* Start of `nix-store --export' operation for serialising a store

path.  This is like `nix-store --dump', only it also dumps the
  meta-information of the store path (references, deriver).  Will add
  a `--sign' flag later to add a cryptographic signature, which we
  will use for exchanging store paths between build farm machines in a
  secure manner.
This commit is contained in:
Eelco Dolstra 2007-02-20 23:17:20 +00:00
parent 3390c1be76
commit b824a1daee
6 changed files with 50 additions and 0 deletions

View file

@ -696,6 +696,24 @@ Path LocalStore::addTextToStore(const string & suffix, const string & s,
} }
void LocalStore::exportPath(const Path & path, bool sign,
Sink & sink)
{
assertStorePath(path);
dumpPath(path, sink);
writeString(path, sink);
PathSet references;
queryReferences(path, references);
writeStringSet(references, sink);
Path deriver = queryDeriver(noTxn, path);
writeString(deriver, sink);
}
void deleteFromStore(const Path & _path, unsigned long long & bytesFreed) void deleteFromStore(const Path & _path, unsigned long long & bytesFreed)
{ {
bytesFreed = 0; bytesFreed = 0;

View file

@ -56,6 +56,9 @@ public:
Path addTextToStore(const string & suffix, const string & s, Path addTextToStore(const string & suffix, const string & s,
const PathSet & references); const PathSet & references);
void exportPath(const Path & path, bool sign,
Sink & sink);
void buildDerivations(const PathSet & drvPaths); void buildDerivations(const PathSet & drvPaths);
void ensurePath(const Path & path); void ensurePath(const Path & path);

View file

@ -243,6 +243,13 @@ Path RemoteStore::addTextToStore(const string & suffix, const string & s,
} }
void RemoteStore::exportPath(const Path & path, bool sign,
Sink & sink)
{
throw Error("not implemented");
}
void RemoteStore::buildDerivations(const PathSet & drvPaths) void RemoteStore::buildDerivations(const PathSet & drvPaths)
{ {
writeInt(wopBuildDerivations, to); writeInt(wopBuildDerivations, to);

View file

@ -44,6 +44,9 @@ public:
Path addTextToStore(const string & suffix, const string & s, Path addTextToStore(const string & suffix, const string & s,
const PathSet & references); const PathSet & references);
void exportPath(const Path & path, bool sign,
Sink & sink);
void buildDerivations(const PathSet & drvPaths); void buildDerivations(const PathSet & drvPaths);
void ensurePath(const Path & path); void ensurePath(const Path & path);

View file

@ -7,6 +7,7 @@
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include "hash.hh" #include "hash.hh"
#include "serialise.hh"
namespace nix { namespace nix {
@ -91,6 +92,13 @@ public:
virtual Path addTextToStore(const string & suffix, const string & s, virtual Path addTextToStore(const string & suffix, const string & s,
const PathSet & references) = 0; const PathSet & references) = 0;
/* Export a store path, that is, create a NAR dump of the store
path and append its references and its deriver. Optionally, a
cryptographic signature (created by OpenSSL) of the preceding
data is attached. */
virtual void exportPath(const Path & path, bool sign,
Sink & sink) = 0;
/* Ensure that the output paths of the derivation are valid. If /* Ensure that the output paths of the derivation are valid. If
they are already valid, this is a no-op. Otherwise, validity they are already valid, this is a no-op. Otherwise, validity
can be reached in two ways. First, if the output paths have can be reached in two ways. First, if the output paths have

View file

@ -638,6 +638,15 @@ static void opRestore(Strings opFlags, Strings opArgs)
} }
static void opExport(Strings opFlags, Strings opArgs)
{
if (!opFlags.empty()) throw UsageError("unknown flag");
FdSink sink(STDOUT_FILENO);
store->exportPath(*opArgs.begin(), false, sink);
}
/* Initialise the Nix databases. */ /* Initialise the Nix databases. */
static void opInit(Strings opFlags, Strings opArgs) static void opInit(Strings opFlags, Strings opArgs)
{ {
@ -707,6 +716,8 @@ void run(Strings args)
op = opDump; op = opDump;
else if (arg == "--restore") else if (arg == "--restore")
op = opRestore; op = opRestore;
else if (arg == "--export")
op = opExport;
else if (arg == "--init") else if (arg == "--init")
op = opInit; op = opInit;
else if (arg == "--verify") else if (arg == "--verify")