about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-07-11T14·43-0400
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-07-11T14·43-0400
commiteb3036da87659fe7cf384c2362e7f7b8b67189a1 (patch)
tree71ed5ae7af671986676f87e7e913355d093ed8da /src
parent6586414bc70c8373faefd49afc5172881f3aad53 (diff)
Implement querySubstitutablePathInfos() in the daemon
Also removed querySubstitutablePathInfo().
Diffstat (limited to 'src')
-rw-r--r--src/libstore/local-store.cc12
-rw-r--r--src/libstore/local-store.hh3
-rw-r--r--src/libstore/remote-store.cc60
-rw-r--r--src/libstore/remote-store.hh3
-rw-r--r--src/libstore/store-api.hh8
-rw-r--r--src/libstore/worker-protocol.hh3
-rw-r--r--src/nix-worker/nix-worker.cc36
7 files changed, 70 insertions, 55 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index b4ea4b748178..339e507957f6 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -967,18 +967,6 @@ void LocalStore::querySubstitutablePathInfos(const Path & substituter,
 }
 
 
-bool LocalStore::querySubstitutablePathInfo(const Path & path,
-    SubstitutablePathInfo & info)
-{
-    SubstitutablePathInfos infos;
-    querySubstitutablePathInfos(singleton<PathSet>(path), infos);
-    SubstitutablePathInfos::iterator i = infos.find(path);
-    if (i == infos.end()) return false;
-    info = i->second;
-    return true;
-}
-
-
 void LocalStore::querySubstitutablePathInfos(const PathSet & paths,
     SubstitutablePathInfos & infos)
 {
diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh
index c4d8be692a36..78217fb71f04 100644
--- a/src/libstore/local-store.hh
+++ b/src/libstore/local-store.hh
@@ -125,9 +125,6 @@ public:
     
     bool hasSubstitutes(const Path & path);
 
-    bool querySubstitutablePathInfo(const Path & path,
-        SubstitutablePathInfo & info);
-    
     void querySubstitutablePathInfos(const Path & substituter,
         PathSet & paths, SubstitutablePathInfos & infos);
     
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc
index 1cf67d3731d1..9579481c7eb5 100644
--- a/src/libstore/remote-store.cc
+++ b/src/libstore/remote-store.cc
@@ -237,34 +237,48 @@ bool RemoteStore::hasSubstitutes(const Path & path)
 }
 
 
-bool RemoteStore::querySubstitutablePathInfo(const Path & path,
-    SubstitutablePathInfo & info)
-{
-    openConnection();
-    if (GET_PROTOCOL_MINOR(daemonVersion) < 3) return false;
-    writeInt(wopQuerySubstitutablePathInfo, to);
-    writeString(path, to);
-    processStderr();
-    unsigned int reply = readInt(from);
-    if (reply == 0) return false;
-    info.deriver = readString(from);
-    if (info.deriver != "") assertStorePath(info.deriver);
-    info.references = readStorePaths<PathSet>(from);
-    info.downloadSize = readLongLong(from);
-    info.narSize = GET_PROTOCOL_MINOR(daemonVersion) >= 7 ? readLongLong(from) : 0;
-    return true;
-}
-
-
 void RemoteStore::querySubstitutablePathInfos(const PathSet & paths,
     SubstitutablePathInfos & infos)
 {
     if (paths.empty()) return;
-    printMsg(lvlError, format("QUERYING %1% (REMOTE)") % showPaths(paths));
-    foreach (PathSet::const_iterator, i, paths) {
-        SubstitutablePathInfo info;
-        if (querySubstitutablePathInfo(*i, info))
+
+    openConnection();
+    
+    if (GET_PROTOCOL_MINOR(daemonVersion) < 3) return;
+    
+    if (GET_PROTOCOL_MINOR(daemonVersion) < 12) {
+        
+        foreach (PathSet::const_iterator, i, paths) {
+            SubstitutablePathInfo info;
+            writeInt(wopQuerySubstitutablePathInfo, to);
+            writeString(*i, to);
+            processStderr();
+            unsigned int reply = readInt(from);
+            if (reply == 0) continue;
+            info.deriver = readString(from);
+            if (info.deriver != "") assertStorePath(info.deriver);
+            info.references = readStorePaths<PathSet>(from);
+            info.downloadSize = readLongLong(from);
+            info.narSize = GET_PROTOCOL_MINOR(daemonVersion) >= 7 ? readLongLong(from) : 0;
             infos[*i] = info;
+        }
+        
+    } else {
+        
+        writeInt(wopQuerySubstitutablePathInfos, to);
+        writeStrings(paths, to);
+        processStderr();
+        unsigned int count = readInt(from);
+        for (unsigned int n = 0; n < count; n++) {
+            Path path = readStorePath(from);
+            SubstitutablePathInfo & info(infos[path]);
+            info.deriver = readString(from);
+            if (info.deriver != "") assertStorePath(info.deriver);
+            info.references = readStorePaths<PathSet>(from);
+            info.downloadSize = readLongLong(from);
+            info.narSize = readLongLong(from);
+        }
+        
     }
 }
 
diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh
index 1056a6115849..c1ac2d05a1f5 100644
--- a/src/libstore/remote-store.hh
+++ b/src/libstore/remote-store.hh
@@ -45,9 +45,6 @@ public:
 
     bool hasSubstitutes(const Path & path);
     
-    bool querySubstitutablePathInfo(const Path & path,
-        SubstitutablePathInfo & info);
-    
     void querySubstitutablePathInfos(const PathSet & paths,
         SubstitutablePathInfos & infos);
     
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index 92b2ddb1e730..37b44d4dac7d 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -145,11 +145,9 @@ public:
     /* Query whether a path has substitutes. */
     virtual bool hasSubstitutes(const Path & path) = 0;
 
-    /* Query the references, deriver and download size of a
-       substitutable path. */
-    virtual bool querySubstitutablePathInfo(const Path & path,
-        SubstitutablePathInfo & info) = 0;
-
+    /* Query substitute info (i.e. references, derivers and download
+       sizes) of a set of paths.  If a path does not have substitute
+       info, it's omitted from the resulting ‘infos’ map. */
     virtual void querySubstitutablePathInfos(const PathSet & paths,
         SubstitutablePathInfos & infos) = 0;
     
diff --git a/src/libstore/worker-protocol.hh b/src/libstore/worker-protocol.hh
index 6a5f0ed40d46..76721d1fc3be 100644
--- a/src/libstore/worker-protocol.hh
+++ b/src/libstore/worker-protocol.hh
@@ -8,7 +8,7 @@ namespace nix {
 #define WORKER_MAGIC_1 0x6e697863
 #define WORKER_MAGIC_2 0x6478696f
 
-#define PROTOCOL_VERSION 0x10b
+#define PROTOCOL_VERSION 0x10c
 #define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00)
 #define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff)
 
@@ -40,6 +40,7 @@ typedef enum {
     wopQueryPathInfo = 26,
     wopImportPaths = 27,
     wopQueryDerivationOutputNames = 28,
+    wopQuerySubstitutablePathInfos = 29,
 } WorkerOp;
 
 
diff --git a/src/nix-worker/nix-worker.cc b/src/nix-worker/nix-worker.cc
index 2f0a2ab209c5..c4a42de12fe1 100644
--- a/src/nix-worker/nix-worker.cc
+++ b/src/nix-worker/nix-worker.cc
@@ -529,16 +529,36 @@ static void performOp(unsigned int clientVersion,
     case wopQuerySubstitutablePathInfo: {
         Path path = absPath(readString(from));
         startWork();
-        SubstitutablePathInfo info;
-        bool res = store->querySubstitutablePathInfo(path, info);
+        SubstitutablePathInfos infos;
+        store->querySubstitutablePathInfos(singleton<PathSet>(path), infos);
         stopWork();
-        writeInt(res ? 1 : 0, to);
-        if (res) {
-            writeString(info.deriver, to);
-            writeStrings(info.references, to);
-            writeLongLong(info.downloadSize, to);
+        SubstitutablePathInfos::iterator i = infos.find(path);
+        if (i == infos.end())
+            writeInt(0, to);
+        else {
+            writeInt(1, to);
+            writeString(i->second.deriver, to);
+            writeStrings(i->second.references, to);
+            writeLongLong(i->second.downloadSize, to);
             if (GET_PROTOCOL_MINOR(clientVersion) >= 7)
-                writeLongLong(info.narSize, to);
+                writeLongLong(i->second.narSize, to);
+        }
+        break;
+    }
+            
+    case wopQuerySubstitutablePathInfos: {
+        PathSet paths = readStorePaths<PathSet>(from);
+        startWork();
+        SubstitutablePathInfos infos;
+        store->querySubstitutablePathInfos(paths, infos);
+        stopWork();
+        writeInt(infos.size(), to);
+        foreach (SubstitutablePathInfos::iterator, i, infos) {
+            writeString(i->first, to);
+            writeString(i->second.deriver, to);
+            writeStrings(i->second.references, to);
+            writeLongLong(i->second.downloadSize, to);
+            writeLongLong(i->second.narSize, to);
         }
         break;
     }