mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-23 14:36:16 +02:00
* First remote operation: isValidPath().
This commit is contained in:
parent
765bdfe542
commit
a711689368
4 changed files with 63 additions and 7 deletions
|
@ -6,7 +6,8 @@ libstore_la_SOURCES = \
|
|||
|
||||
pkginclude_HEADERS = \
|
||||
store-api.hh local-store.cc remote-store.cc derivations.hh misc.hh \
|
||||
globals.hh db.hh references.hh pathlocks.hh gc.hh
|
||||
globals.hh db.hh references.hh pathlocks.hh gc.hh \
|
||||
worker-protocol.hh
|
||||
|
||||
libstore_la_LIBADD = ../libutil/libutil.la ../boost/format/libformat.la
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "serialise.hh"
|
||||
#include "util.hh"
|
||||
#include "remote-store.hh"
|
||||
#include "worker-protocol.hh"
|
||||
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
|
@ -55,27 +56,36 @@ RemoteStore::RemoteStore()
|
|||
|
||||
|
||||
/* Send the magic greeting, check for the reply. */
|
||||
writeInt(0x6e697864, to);
|
||||
writeInt(WORKER_MAGIC_1, to);
|
||||
|
||||
unsigned int magic = readInt(from);
|
||||
if (magic != 0x6478696e) throw Error("protocol mismatch");
|
||||
if (magic != WORKER_MAGIC_2) throw Error("protocol mismatch");
|
||||
}
|
||||
|
||||
|
||||
RemoteStore::~RemoteStore()
|
||||
{
|
||||
writeInt(wopQuit, to);
|
||||
readInt(from);
|
||||
child.wait(true);
|
||||
}
|
||||
|
||||
|
||||
bool RemoteStore::isValidPath(const Path & path)
|
||||
{
|
||||
throw Error("not implemented");
|
||||
writeInt(wopIsValidPath, to);
|
||||
writeString(path, to);
|
||||
unsigned int reply = readInt(from);
|
||||
return reply != 0;
|
||||
}
|
||||
|
||||
|
||||
Substitutes RemoteStore::querySubstitutes(const Path & srcPath)
|
||||
{
|
||||
throw Error("not implemented");
|
||||
// writeInt(wopQuerySubstitutes);
|
||||
|
||||
// throw Error("not implemented 2");
|
||||
return Substitutes();
|
||||
}
|
||||
|
||||
|
||||
|
|
16
src/libstore/worker-protocol.hh
Normal file
16
src/libstore/worker-protocol.hh
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef __WORKER_PROTOCOL_H
|
||||
#define __WORKER_PROTOCOL_H
|
||||
|
||||
|
||||
#define WORKER_MAGIC_1 0x6e697864
|
||||
#define WORKER_MAGIC_2 0x6478696e
|
||||
|
||||
|
||||
typedef enum {
|
||||
wopQuit = 0,
|
||||
wopIsValidPath = 1,
|
||||
wopQuerySubstitutes = 2,
|
||||
} WorkerOp;
|
||||
|
||||
|
||||
#endif /* !__WORKER_PROTOCOL_H */
|
|
@ -2,6 +2,7 @@
|
|||
#include "local-store.hh"
|
||||
#include "util.hh"
|
||||
#include "serialise.hh"
|
||||
#include "worker-protocol.hh"
|
||||
|
||||
using namespace nix;
|
||||
|
||||
|
@ -11,11 +12,39 @@ void processConnection(Source & from, Sink & to)
|
|||
store = boost::shared_ptr<StoreAPI>(new LocalStore(true));
|
||||
|
||||
unsigned int magic = readInt(from);
|
||||
if (magic != 0x6e697864) throw Error("protocol mismatch");
|
||||
if (magic != WORKER_MAGIC_1) throw Error("protocol mismatch");
|
||||
|
||||
writeInt(0x6478696e, to);
|
||||
writeInt(WORKER_MAGIC_2, to);
|
||||
|
||||
debug("greeting exchanged");
|
||||
|
||||
bool quit = false;
|
||||
|
||||
do {
|
||||
|
||||
WorkerOp op = (WorkerOp) readInt(from);
|
||||
|
||||
switch (op) {
|
||||
|
||||
case wopQuit:
|
||||
/* Close the database. */
|
||||
store.reset((StoreAPI *) 0);
|
||||
writeInt(1, to);
|
||||
quit = true;
|
||||
break;
|
||||
|
||||
case wopIsValidPath: {
|
||||
Path path = readString(from);
|
||||
assertStorePath(path);
|
||||
writeInt(store->isValidPath(path), to);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
throw Error("invalid operation");
|
||||
}
|
||||
|
||||
} while (!quit);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue