aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/remote-store.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore/remote-store.cc')
-rw-r--r--src/libstore/remote-store.cc135
1 files changed, 54 insertions, 81 deletions
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc
index 82b7cfd7c..5a254a610 100644
--- a/src/libstore/remote-store.cc
+++ b/src/libstore/remote-store.cc
@@ -49,6 +49,12 @@ RemoteStore::RemoteStore(size_t maxConnections)
}
+std::string RemoteStore::getUri()
+{
+ return "daemon";
+}
+
+
ref<RemoteStore::Connection> RemoteStore::openConnection()
{
auto conn = make_ref<Connection>();
@@ -61,27 +67,15 @@ ref<RemoteStore::Connection> RemoteStore::openConnection()
string socketPath = settings.nixDaemonSocketFile;
- /* Urgh, sockaddr_un allows path names of only 108 characters. So
- chdir to the socket directory so that we can pass a relative
- path name. !!! this is probably a bad idea in multi-threaded
- applications... */
- AutoCloseFD fdPrevDir = open(".", O_RDONLY);
- if (fdPrevDir == -1) throw SysError("couldn't open current directory");
- if (chdir(dirOf(socketPath).c_str()) == -1) throw SysError(format("couldn't change to directory of ‘%1%’") % socketPath);
- Path socketPathRel = "./" + baseNameOf(socketPath);
-
struct sockaddr_un addr;
addr.sun_family = AF_UNIX;
- if (socketPathRel.size() >= sizeof(addr.sun_path))
- throw Error(format("socket path ‘%1%’ is too long") % socketPathRel);
- strcpy(addr.sun_path, socketPathRel.c_str());
+ if (socketPath.size() + 1 >= sizeof(addr.sun_path))
+ throw Error(format("socket path ‘%1%’ is too long") % socketPath);
+ strcpy(addr.sun_path, socketPath.c_str());
if (connect(conn->fd, (struct sockaddr *) &addr, sizeof(addr)) == -1)
throw SysError(format("cannot connect to daemon at ‘%1%’") % socketPath);
- if (fchdir(fdPrevDir) == -1)
- throw SysError("couldn't change back to previous directory");
-
conn->from.fd = conn->fd;
conn->to.fd = conn->fd;
@@ -132,9 +126,9 @@ void RemoteStore::setOptions(ref<Connection> conn)
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 2)
conn->to << settings.useBuildHook;
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 4)
- conn->to << settings.buildVerbosity
- << logType
- << settings.printBuildTrace;
+ conn->to << (settings.verboseBuild ? lvlError : lvlVomit)
+ << 0 // obsolete log type
+ << 0 /* obsolete print build trace */;
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 6)
conn->to << settings.buildCores;
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 10)
@@ -153,7 +147,7 @@ void RemoteStore::setOptions(ref<Connection> conn)
}
-bool RemoteStore::isValidPath(const Path & path)
+bool RemoteStore::isValidPathUncached(const Path & path)
{
auto conn(connections->get());
conn->to << wopIsValidPath << path;
@@ -251,44 +245,38 @@ void RemoteStore::querySubstitutablePathInfos(const PathSet & paths,
}
-ValidPathInfo RemoteStore::queryPathInfo(const Path & path)
+std::shared_ptr<ValidPathInfo> RemoteStore::queryPathInfoUncached(const Path & path)
{
auto conn(connections->get());
conn->to << wopQueryPathInfo << path;
- conn->processStderr();
- ValidPathInfo info;
- info.path = path;
- info.deriver = readString(conn->from);
- if (info.deriver != "") assertStorePath(info.deriver);
- info.narHash = parseHash(htSHA256, readString(conn->from));
- info.references = readStorePaths<PathSet>(conn->from);
- info.registrationTime = readInt(conn->from);
- info.narSize = readLongLong(conn->from);
+ try {
+ conn->processStderr();
+ } catch (Error & e) {
+ // Ugly backwards compatibility hack.
+ if (e.msg().find("is not valid") != std::string::npos)
+ throw InvalidPath(e.what());
+ throw;
+ }
+ if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 17) {
+ bool valid = readInt(conn->from) != 0;
+ if (!valid) throw InvalidPath(format("path ‘%s’ is not valid") % path);
+ }
+ auto info = std::make_shared<ValidPathInfo>();
+ info->path = path;
+ info->deriver = readString(conn->from);
+ if (info->deriver != "") assertStorePath(info->deriver);
+ info->narHash = parseHash(htSHA256, readString(conn->from));
+ info->references = readStorePaths<PathSet>(conn->from);
+ info->registrationTime = readInt(conn->from);
+ info->narSize = readLongLong(conn->from);
+ if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 16) {
+ info->ultimate = readInt(conn->from) != 0;
+ info->sigs = readStrings<StringSet>(conn->from);
+ }
return info;
}
-Hash RemoteStore::queryPathHash(const Path & path)
-{
- auto conn(connections->get());
- conn->to << wopQueryPathHash << path;
- conn->processStderr();
- string hash = readString(conn->from);
- return parseHash(htSHA256, hash);
-}
-
-
-void RemoteStore::queryReferences(const Path & path,
- PathSet & references)
-{
- auto conn(connections->get());
- conn->to << wopQueryReferences << path;
- conn->processStderr();
- PathSet references2 = readStorePaths<PathSet>(conn->from);
- references.insert(references2.begin(), references2.end());
-}
-
-
void RemoteStore::queryReferrers(const Path & path,
PathSet & referrers)
{
@@ -300,17 +288,6 @@ void RemoteStore::queryReferrers(const Path & path,
}
-Path RemoteStore::queryDeriver(const Path & path)
-{
- auto conn(connections->get());
- conn->to << wopQueryDeriver << path;
- conn->processStderr();
- Path drvPath = readString(conn->from);
- if (drvPath != "") assertStorePath(drvPath);
- return drvPath;
-}
-
-
PathSet RemoteStore::queryValidDerivers(const Path & path)
{
auto conn(connections->get());
@@ -525,26 +502,14 @@ void RemoteStore::collectGarbage(const GCOptions & options, GCResults & results)
results.paths = readStrings<PathSet>(conn->from);
results.bytesFreed = readLongLong(conn->from);
readLongLong(conn->from); // obsolete
-}
-
-PathSet RemoteStore::queryFailedPaths()
-{
- auto conn(connections->get());
- conn->to << wopQueryFailedPaths;
- conn->processStderr();
- return readStorePaths<PathSet>(conn->from);
+ {
+ auto state_(Store::state.lock());
+ state_->pathInfoCache.clear();
+ }
}
-void RemoteStore::clearFailedPaths(const PathSet & paths)
-{
- auto conn(connections->get());
- conn->to << wopClearFailedPaths << paths;
- conn->processStderr();
- readInt(conn->from);
-}
-
void RemoteStore::optimiseStore()
{
auto conn(connections->get());
@@ -553,6 +518,7 @@ void RemoteStore::optimiseStore()
readInt(conn->from);
}
+
bool RemoteStore::verifyStore(bool checkContents, bool repair)
{
auto conn(connections->get());
@@ -562,6 +528,15 @@ bool RemoteStore::verifyStore(bool checkContents, bool repair)
}
+void RemoteStore::addSignatures(const Path & storePath, const StringSet & sigs)
+{
+ auto conn(connections->get());
+ conn->to << wopAddSignatures << storePath << sigs;
+ conn->processStderr();
+ readInt(conn->from);
+}
+
+
RemoteStore::Connection::~Connection()
{
try {
@@ -592,10 +567,8 @@ void RemoteStore::Connection::processStderr(Sink * sink, Source * source)
writeString(buf, source->read(buf, len), to);
to.flush();
}
- else {
- string s = readString(from);
- writeToStderr(s);
- }
+ else
+ printMsg(lvlError, chomp(readString(from)));
}
if (msg == STDERR_ERROR) {
string error = readString(from);