* Skeleton of the privileged worker program.

* Some refactoring: put the NAR archive integer/string serialisation
  code in a separate file so it can be reused by the worker protocol
  implementation.
This commit is contained in:
Eelco Dolstra 2006-11-30 19:19:59 +00:00
parent 9adc074dc3
commit 40b3f64b55
12 changed files with 255 additions and 126 deletions

View file

@ -607,17 +607,6 @@ static void opDelete(Strings opFlags, Strings opArgs)
}
/* A sink that writes dump output to stdout. */
struct StdoutSink : DumpSink
{
virtual void operator ()
(const unsigned char * data, unsigned int len)
{
writeFull(STDOUT_FILENO, data, len);
}
};
/* Dump a path as a Nix archive. The archive is written to standard
output. */
static void opDump(Strings opFlags, Strings opArgs)
@ -625,22 +614,12 @@ static void opDump(Strings opFlags, Strings opArgs)
if (!opFlags.empty()) throw UsageError("unknown flag");
if (opArgs.size() != 1) throw UsageError("only one argument allowed");
StdoutSink sink;
FdSink sink(STDOUT_FILENO);
string path = *opArgs.begin();
dumpPath(path, sink);
}
/* A source that reads restore input from stdin. */
struct StdinSource : RestoreSource
{
virtual void operator () (unsigned char * data, unsigned int len)
{
readFull(STDIN_FILENO, data, len);
}
};
/* Restore a value from a Nix archive. The archive is read from
standard input. */
static void opRestore(Strings opFlags, Strings opArgs)
@ -648,7 +627,7 @@ static void opRestore(Strings opFlags, Strings opArgs)
if (!opFlags.empty()) throw UsageError("unknown flag");
if (opArgs.size() != 1) throw UsageError("only one argument allowed");
StdinSource source;
FdSource source(STDIN_FILENO);
restorePath(*opArgs.begin(), source);
}