about summary refs log tree commit diff
path: root/src/nix-store/nix-store.cc
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2014-02-10T11·52-0500
committerShea Levy <shea@shealevy.com>2014-02-10T11·52-0500
commit38c3beac1a8ac9ddf4fdbbcafd400dabcf195076 (patch)
treee6b1d1f111c18d9d01a9ffa401d0e93568fa01ed /src/nix-store/nix-store.cc
parent16146031659eae475cd5933b8553b13d725ca436 (diff)
Move StoreApi::serve into opServe
Signed-off-by: Shea Levy <shea@shealevy.com>
Diffstat (limited to 'src/nix-store/nix-store.cc')
-rw-r--r--src/nix-store/nix-store.cc30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc
index e3f27820fffd..68ad9026747f 100644
--- a/src/nix-store/nix-store.cc
+++ b/src/nix-store/nix-store.cc
@@ -839,10 +839,38 @@ static void opServe(Strings opFlags, Strings opArgs)
 {
     if (!opArgs.empty() || !opFlags.empty())
         throw UsageError("no arguments or flags expected");
+
     FdSource in(STDIN_FILENO);
     FdSink out(STDOUT_FILENO);
 
-    store->serve(in, out);
+    string cmd = readString(in);
+    if (cmd == "query") {
+        for (cmd = readString(in); !cmd.empty(); cmd = readString(in)) {
+            PathSet paths = readStrings<PathSet>(in);
+            if (cmd == "have") {
+                writeStrings(store->queryValidPaths(paths), out);
+            } else if (cmd == "info") {
+                // !!! Maybe we want a queryPathInfos?
+                foreach (PathSet::iterator, i, paths) {
+                    if (!store->isValidPath(*i))
+                        continue;
+                    ValidPathInfo info = store->queryPathInfo(*i);
+                    writeString(info.path, out);
+                    writeString(info.deriver, out);
+                    writeStrings(info.references, out);
+                    // !!! Maybe we want compression?
+                    writeLongLong(info.narSize, out); // downloadSize
+                    writeLongLong(info.narSize, out);
+                }
+                writeString("", out);
+            } else
+                throw Error(format("Unknown serve query `%1%'") % cmd);
+            out.flush();
+        }
+    } else if (cmd == "substitute")
+        dumpPath(readString(in), out);
+    else
+        throw Error(format("Unknown serve command `%1%'") % cmd);
 }