Skip to content

Commit 0f5da8a

Browse files
committed
* Support exportPath() in remote mode.
1 parent dc7d594 commit 0f5da8a

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

src/libstore/remote-store.cc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,11 @@ Path RemoteStore::addTextToStore(const string & suffix, const string & s,
246246
void RemoteStore::exportPath(const Path & path, bool sign,
247247
Sink & sink)
248248
{
249-
throw Error("not implemented");
249+
writeInt(wopExportPath, to);
250+
writeString(path, to);
251+
writeInt(sign ? 1 : 0, to);
252+
processStderr(&sink); /* sink receives the actual data */
253+
readInt(from);
250254
}
251255

252256

@@ -336,12 +340,16 @@ void RemoteStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
336340
}
337341

338342

339-
void RemoteStore::processStderr()
343+
void RemoteStore::processStderr(Sink * sink)
340344
{
341345
unsigned int msg;
342-
while ((msg = readInt(from)) == STDERR_NEXT) {
346+
while ((msg = readInt(from)) == STDERR_NEXT || msg == STDERR_DATA) {
343347
string s = readString(from);
344-
writeToStderr((unsigned char *) s.c_str(), s.size());
348+
if (msg == STDERR_DATA) {
349+
if (!sink) throw Error("no sink");
350+
(*sink)((const unsigned char *) s.c_str(), s.size());
351+
}
352+
else writeToStderr((const unsigned char *) s.c_str(), s.size());
345353
}
346354
if (msg == STDERR_ERROR)
347355
throw Error(readString(from));

src/libstore/remote-store.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private:
7070
FdSource from;
7171
Pid child;
7272

73-
void processStderr();
73+
void processStderr(Sink * sink = 0);
7474

7575
void forkSlave();
7676

src/libstore/worker-protocol.hh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ typedef enum {
2626
wopSyncWithGC,
2727
wopFindRoots,
2828
wopCollectGarbage,
29+
wopExportPath,
30+
wopImportPath,
2931
} WorkerOp;
3032

3133

3234
#define STDERR_NEXT 0x6f6c6d67
35+
#define STDERR_DATA 0x64617461
3336
#define STDERR_LAST 0x616c7473
3437
#define STDERR_ERROR 0x63787470
3538

src/nix-worker/nix-worker.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,21 @@ static void stopWork(bool success = true, const string & msg = "")
178178
}
179179

180180

181+
struct TunnelSink : Sink
182+
{
183+
Sink & to;
184+
TunnelSink(Sink & to) : to(to)
185+
{
186+
}
187+
virtual void operator ()
188+
(const unsigned char * data, unsigned int len)
189+
{
190+
writeInt(STDERR_DATA, to);
191+
writeString(string((const char *) data, len), to);
192+
}
193+
};
194+
195+
181196
static void performOp(Source & from, Sink & to, unsigned int op)
182197
{
183198
switch (op) {
@@ -263,6 +278,17 @@ static void performOp(Source & from, Sink & to, unsigned int op)
263278
break;
264279
}
265280

281+
case wopExportPath: {
282+
Path path = readStorePath(from);
283+
bool sign = readInt(from) == 1;
284+
startWork();
285+
TunnelSink sink(to);
286+
store->exportPath(path, sign, sink);
287+
stopWork();
288+
writeInt(1, to);
289+
break;
290+
}
291+
266292
case wopBuildDerivations: {
267293
PathSet drvs = readStorePaths(from);
268294
startWork();

0 commit comments

Comments
 (0)