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,
SubstitutablePathInfos & infos)
{

View file

@ -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);

View file

@ -237,34 +237,48 @@ bool RemoteStore::hasSubstitutes(const Path & path)
}
bool RemoteStore::querySubstitutablePathInfo(const Path & path,
SubstitutablePathInfo & info)
void RemoteStore::querySubstitutablePathInfos(const PathSet & paths,
SubstitutablePathInfos & infos)
{
if (paths.empty()) return;
openConnection();
if (GET_PROTOCOL_MINOR(daemonVersion) < 3) return false;
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(path, to);
writeString(*i, to);
processStderr();
unsigned int reply = readInt(from);
if (reply == 0) return false;
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;
return true;
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);
}
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))
infos[*i] = info;
}
}

View file

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

View file

@ -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;

View file

@ -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;

View file

@ -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;
}