From 38c3beac1a8ac9ddf4fdbbcafd400dabcf195076 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Mon, 10 Feb 2014 06:52:48 -0500 Subject: Move StoreApi::serve into opServe Signed-off-by: Shea Levy --- src/libstore/store-api.cc | 34 ---------------------------------- src/libstore/store-api.hh | 4 ---- src/nix-store/nix-store.cc | 30 +++++++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 39 deletions(-) diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index e4f180240992..0f250a3c7c04 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -1,7 +1,6 @@ #include "store-api.hh" #include "globals.hh" #include "util.hh" -#include "archive.hh" #include @@ -259,39 +258,6 @@ string StoreAPI::makeValidityRegistration(const PathSet & paths, } -void StoreAPI::serve(Source & in, BufferedSink & out) -{ - string cmd = readString(in); - if (cmd == "query") { - for (cmd = readString(in); !cmd.empty(); cmd = readString(in)) { - PathSet paths = readStrings(in); - if (cmd == "have") { - writeStrings(queryValidPaths(paths), out); - } else if (cmd == "info") { - // !!! Maybe we want a queryPathInfos? - foreach (PathSet::iterator, i, paths) { - if (!isValidPath(*i)) - continue; - ValidPathInfo info = 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); -} - - ValidPathInfo decodeValidPathInfo(std::istream & str, bool hashGiven) { ValidPathInfo info; diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index f32824a3bb7c..a82fe3221639 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -248,10 +248,6 @@ public: `nix-store --register-validity'. */ string makeValidityRegistration(const PathSet & paths, bool showDerivers, bool showHash); - - /* Serve the store for ssh substituters by taking commands - * from in and printing results to out */ - void serve(Source & in, BufferedSink & out); }; 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(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); } -- cgit 1.4.1