Implement querySubstitutablePathInfos() in the daemon

Also removed querySubstitutablePathInfo().
This commit is contained in:
Eelco Dolstra 2012-07-11 10:43:24 -04:00
parent 6586414bc7
commit eb3036da87
7 changed files with 70 additions and 55 deletions

View File

@ -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, void LocalStore::querySubstitutablePathInfos(const PathSet & paths,
SubstitutablePathInfos & infos) SubstitutablePathInfos & infos)
{ {

View File

@ -125,9 +125,6 @@ public:
bool hasSubstitutes(const Path & path); bool hasSubstitutes(const Path & path);
bool querySubstitutablePathInfo(const Path & path,
SubstitutablePathInfo & info);
void querySubstitutablePathInfos(const Path & substituter, void querySubstitutablePathInfos(const Path & substituter,
PathSet & paths, SubstitutablePathInfos & infos); PathSet & paths, SubstitutablePathInfos & infos);

View File

@ -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, void RemoteStore::querySubstitutablePathInfos(const PathSet & paths,
SubstitutablePathInfos & infos) SubstitutablePathInfos & infos)
{ {
if (paths.empty()) return; if (paths.empty()) return;
printMsg(lvlError, format("QUERYING %1% (REMOTE)") % showPaths(paths));
foreach (PathSet::const_iterator, i, paths) { openConnection();
SubstitutablePathInfo info;
if (querySubstitutablePathInfo(*i, info)) 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; 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);
}
} }
} }

View File

@ -45,9 +45,6 @@ public:
bool hasSubstitutes(const Path & path); bool hasSubstitutes(const Path & path);
bool querySubstitutablePathInfo(const Path & path,
SubstitutablePathInfo & info);
void querySubstitutablePathInfos(const PathSet & paths, void querySubstitutablePathInfos(const PathSet & paths,
SubstitutablePathInfos & infos); SubstitutablePathInfos & infos);

View File

@ -145,11 +145,9 @@ public:
/* Query whether a path has substitutes. */ /* Query whether a path has substitutes. */
virtual bool hasSubstitutes(const Path & path) = 0; virtual bool hasSubstitutes(const Path & path) = 0;
/* Query the references, deriver and download size of a /* Query substitute info (i.e. references, derivers and download
substitutable path. */ sizes) of a set of paths. If a path does not have substitute
virtual bool querySubstitutablePathInfo(const Path & path, info, it's omitted from the resulting infos map. */
SubstitutablePathInfo & info) = 0;
virtual void querySubstitutablePathInfos(const PathSet & paths, virtual void querySubstitutablePathInfos(const PathSet & paths,
SubstitutablePathInfos & infos) = 0; SubstitutablePathInfos & infos) = 0;

View File

@ -8,7 +8,7 @@ namespace nix {
#define WORKER_MAGIC_1 0x6e697863 #define WORKER_MAGIC_1 0x6e697863
#define WORKER_MAGIC_2 0x6478696f #define WORKER_MAGIC_2 0x6478696f
#define PROTOCOL_VERSION 0x10b #define PROTOCOL_VERSION 0x10c
#define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00) #define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00)
#define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff) #define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff)
@ -40,6 +40,7 @@ typedef enum {
wopQueryPathInfo = 26, wopQueryPathInfo = 26,
wopImportPaths = 27, wopImportPaths = 27,
wopQueryDerivationOutputNames = 28, wopQueryDerivationOutputNames = 28,
wopQuerySubstitutablePathInfos = 29,
} WorkerOp; } WorkerOp;

View File

@ -529,16 +529,36 @@ static void performOp(unsigned int clientVersion,
case wopQuerySubstitutablePathInfo: { case wopQuerySubstitutablePathInfo: {
Path path = absPath(readString(from)); Path path = absPath(readString(from));
startWork(); startWork();
SubstitutablePathInfo info; SubstitutablePathInfos infos;
bool res = store->querySubstitutablePathInfo(path, info); store->querySubstitutablePathInfos(singleton<PathSet>(path), infos);
stopWork(); stopWork();
writeInt(res ? 1 : 0, to); SubstitutablePathInfos::iterator i = infos.find(path);
if (res) { if (i == infos.end())
writeString(info.deriver, to); writeInt(0, to);
writeStrings(info.references, to); else {
writeLongLong(info.downloadSize, to); writeInt(1, to);
writeString(i->second.deriver, to);
writeStrings(i->second.references, to);
writeLongLong(i->second.downloadSize, to);
if (GET_PROTOCOL_MINOR(clientVersion) >= 7) 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; break;
} }