Skip to content

Commit a711689

Browse files
committed
* First remote operation: isValidPath().
1 parent 765bdfe commit a711689

File tree

4 files changed

+63
-7
lines changed

4 files changed

+63
-7
lines changed

src/libstore/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ libstore_la_SOURCES = \
66

77
pkginclude_HEADERS = \
88
store-api.hh local-store.cc remote-store.cc derivations.hh misc.hh \
9-
globals.hh db.hh references.hh pathlocks.hh gc.hh
9+
globals.hh db.hh references.hh pathlocks.hh gc.hh \
10+
worker-protocol.hh
1011

1112
libstore_la_LIBADD = ../libutil/libutil.la ../boost/format/libformat.la
1213

src/libstore/remote-store.cc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "serialise.hh"
22
#include "util.hh"
33
#include "remote-store.hh"
4+
#include "worker-protocol.hh"
45

56
#include <iostream>
67
#include <unistd.h>
@@ -55,27 +56,36 @@ RemoteStore::RemoteStore()
5556

5657

5758
/* Send the magic greeting, check for the reply. */
58-
writeInt(0x6e697864, to);
59+
writeInt(WORKER_MAGIC_1, to);
5960

6061
unsigned int magic = readInt(from);
61-
if (magic != 0x6478696e) throw Error("protocol mismatch");
62+
if (magic != WORKER_MAGIC_2) throw Error("protocol mismatch");
6263
}
6364

6465

6566
RemoteStore::~RemoteStore()
6667
{
68+
writeInt(wopQuit, to);
69+
readInt(from);
70+
child.wait(true);
6771
}
6872

6973

7074
bool RemoteStore::isValidPath(const Path & path)
7175
{
72-
throw Error("not implemented");
76+
writeInt(wopIsValidPath, to);
77+
writeString(path, to);
78+
unsigned int reply = readInt(from);
79+
return reply != 0;
7380
}
7481

7582

7683
Substitutes RemoteStore::querySubstitutes(const Path & srcPath)
7784
{
78-
throw Error("not implemented");
85+
// writeInt(wopQuerySubstitutes);
86+
87+
// throw Error("not implemented 2");
88+
return Substitutes();
7989
}
8090

8191

src/libstore/worker-protocol.hh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef __WORKER_PROTOCOL_H
2+
#define __WORKER_PROTOCOL_H
3+
4+
5+
#define WORKER_MAGIC_1 0x6e697864
6+
#define WORKER_MAGIC_2 0x6478696e
7+
8+
9+
typedef enum {
10+
wopQuit = 0,
11+
wopIsValidPath = 1,
12+
wopQuerySubstitutes = 2,
13+
} WorkerOp;
14+
15+
16+
#endif /* !__WORKER_PROTOCOL_H */

src/nix-worker/main.cc

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "local-store.hh"
33
#include "util.hh"
44
#include "serialise.hh"
5+
#include "worker-protocol.hh"
56

67
using namespace nix;
78

@@ -11,11 +12,39 @@ void processConnection(Source & from, Sink & to)
1112
store = boost::shared_ptr<StoreAPI>(new LocalStore(true));
1213

1314
unsigned int magic = readInt(from);
14-
if (magic != 0x6e697864) throw Error("protocol mismatch");
15+
if (magic != WORKER_MAGIC_1) throw Error("protocol mismatch");
1516

16-
writeInt(0x6478696e, to);
17+
writeInt(WORKER_MAGIC_2, to);
1718

1819
debug("greeting exchanged");
20+
21+
bool quit = false;
22+
23+
do {
24+
25+
WorkerOp op = (WorkerOp) readInt(from);
26+
27+
switch (op) {
28+
29+
case wopQuit:
30+
/* Close the database. */
31+
store.reset((StoreAPI *) 0);
32+
writeInt(1, to);
33+
quit = true;
34+
break;
35+
36+
case wopIsValidPath: {
37+
Path path = readString(from);
38+
assertStorePath(path);
39+
writeInt(store->isValidPath(path), to);
40+
break;
41+
}
42+
43+
default:
44+
throw Error("invalid operation");
45+
}
46+
47+
} while (!quit);
1948
}
2049

2150

0 commit comments

Comments
 (0)