about summary refs log tree commit diff
path: root/src/libstore/remote-store.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2007-02-21T17·34+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2007-02-21T17·34+0000
commitbdadb98de8fcd5ed99cca97071741e2775f3ada2 (patch)
treee00b997c3dd90baafeb20fbf2ac2b89e87b2d325 /src/libstore/remote-store.cc
parent0f5da8a83c227879566ed87623617fe195bc6f88 (diff)
* `nix-store --import' now also works in remote mode. The worker
  always requires a signature on the archive.  This is to ensure that
  unprivileged users cannot add Trojan horses to the Nix store.

Diffstat (limited to 'src/libstore/remote-store.cc')
-rw-r--r--src/libstore/remote-store.cc30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc
index dbeb7cf122..1aab90d38c 100644
--- a/src/libstore/remote-store.cc
+++ b/src/libstore/remote-store.cc
@@ -256,7 +256,13 @@ void RemoteStore::exportPath(const Path & path, bool sign,
 
 Path RemoteStore::importPath(bool requireSignature, Source & source)
 {
-    throw Error("not implemented");
+    writeInt(wopImportPath, to);
+    /* We ignore requireSignature, since the worker forces it to true
+       anyway. */
+    
+    processStderr(0, &source);
+    Path path = readStorePath(from);
+    return path;
 }
 
 
@@ -340,16 +346,28 @@ void RemoteStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
 }
 
 
-void RemoteStore::processStderr(Sink * sink)
+void RemoteStore::processStderr(Sink * sink, Source * source)
 {
     unsigned int msg;
-    while ((msg = readInt(from)) == STDERR_NEXT || msg == STDERR_DATA) {
-        string s = readString(from);
-        if (msg == STDERR_DATA) {
+    while ((msg = readInt(from)) == STDERR_NEXT
+        || msg == STDERR_READ || msg == STDERR_WRITE) {
+        if (msg == STDERR_WRITE) {
+            string s = readString(from);
             if (!sink) throw Error("no sink");
             (*sink)((const unsigned char *) s.c_str(), s.size());
         }
-        else writeToStderr((const unsigned char *) s.c_str(), s.size());
+        else if (msg == STDERR_READ) {
+            if (!source) throw Error("no source");
+            unsigned int len = readInt(from);
+            unsigned char * buf = new unsigned char[len];
+            AutoDeleteArray<unsigned char> d(buf);
+            (*source)(buf, len);
+            writeString(string((const char *) buf, len), to);
+        }
+        else {
+            string s = readString(from);
+            writeToStderr((const unsigned char *) s.c_str(), s.size());
+        }
     }
     if (msg == STDERR_ERROR)
         throw Error(readString(from));