Skip to content

Commit ddea253

Browse files
committed
RemoteStore: Propagate InvalidPath exceptions from the daemon
1 parent c0c4ddc commit ddea253

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

src/libstore/remote-store.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,18 @@ std::shared_ptr<ValidPathInfo> RemoteStore::queryPathInfoUncached(const Path & p
243243
{
244244
auto conn(connections->get());
245245
conn->to << wopQueryPathInfo << path;
246-
conn->processStderr();
246+
try {
247+
conn->processStderr();
248+
} catch (Error & e) {
249+
// Ugly backwards compatibility hack.
250+
if (e.msg().find("is not valid") != std::string::npos)
251+
throw InvalidPath(e.what());
252+
throw;
253+
}
254+
if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 17) {
255+
bool valid = readInt(conn->from) != 0;
256+
if (!valid) throw InvalidPath(format("path ‘%s’ is not valid") % path);
257+
}
247258
auto info = std::make_shared<ValidPathInfo>();
248259
info->path = path;
249260
info->deriver = readString(conn->from);

src/libstore/worker-protocol.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace nix {
66
#define WORKER_MAGIC_1 0x6e697863
77
#define WORKER_MAGIC_2 0x6478696f
88

9-
#define PROTOCOL_VERSION 0x110
9+
#define PROTOCOL_VERSION 0x111
1010
#define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00)
1111
#define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff)
1212

src/nix-daemon/nix-daemon.cc

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -495,15 +495,23 @@ static void performOp(ref<LocalStore> store, bool trusted, unsigned int clientVe
495495

496496
case wopQueryPathInfo: {
497497
Path path = readStorePath(from);
498+
std::shared_ptr<const ValidPathInfo> info;
498499
startWork();
499-
auto info = store->queryPathInfo(path);
500-
stopWork();
501-
to << info->deriver << printHash(info->narHash) << info->references
502-
<< info->registrationTime << info->narSize;
503-
if (GET_PROTOCOL_MINOR(clientVersion) >= 16) {
504-
to << info->ultimate
505-
<< info->sigs;
500+
try {
501+
info = store->queryPathInfo(path);
502+
} catch (InvalidPath &) {
503+
if (GET_PROTOCOL_MINOR(clientVersion) < 17) throw;
506504
}
505+
stopWork();
506+
if (info) {
507+
to << 1 << info->deriver << printHash(info->narHash) << info->references
508+
<< info->registrationTime << info->narSize;
509+
if (GET_PROTOCOL_MINOR(clientVersion) >= 16) {
510+
to << info->ultimate
511+
<< info->sigs;
512+
}
513+
} else
514+
to << 0;
507515
break;
508516
}
509517

0 commit comments

Comments
 (0)