From eb3036da87659fe7cf384c2362e7f7b8b67189a1 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 11 Jul 2012 10:43:24 -0400 Subject: [PATCH] Implement querySubstitutablePathInfos() in the daemon Also removed querySubstitutablePathInfo(). --- src/libstore/local-store.cc | 12 ------- src/libstore/local-store.hh | 3 -- src/libstore/remote-store.cc | 60 ++++++++++++++++++++------------- src/libstore/remote-store.hh | 3 -- src/libstore/store-api.hh | 8 ++--- src/libstore/worker-protocol.hh | 3 +- src/nix-worker/nix-worker.cc | 36 +++++++++++++++----- 7 files changed, 70 insertions(+), 55 deletions(-) diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index b4ea4b7481..339e507957 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(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 c4d8be692a..78217fb71f 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 1cf67d3731..9579481c7e 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(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(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(from); + info.downloadSize = readLongLong(from); + info.narSize = readLongLong(from); + } + } } diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh index 1056a61158..c1ac2d05a1 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 92b2ddb1e7..37b44d4dac 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 6a5f0ed40d..76721d1fc3 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 2f0a2ab209..c4a42de12f 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(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(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; }