about summary refs log tree commit diff
path: root/third_party/nix/src/nix-daemon/nix-daemon-proto.cc
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2020-07-16T23·11+0100
committertazjin <mail@tazj.in>2020-07-16T23·20+0000
commit5c9af8faee5c061a0d75f6f0773dd2ddcdb36adc (patch)
tree80f645ece96c7724b434fc1e7c28d8bd5fb92a45 /third_party/nix/src/nix-daemon/nix-daemon-proto.cc
parent32735eebdd18f92e526d06a2f4b4a04e27998d03 (diff)
feat(3p/nix): Implement similar group of Worker::Query* handlers r/1340
These are the queries that are handled in the confusing case statement
in the old daemon implementation, because they have very similar
structure.

Change-Id: Ie7143354f66cef4336dff8072ede9a56271a7e89
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1228
Tested-by: BuildkiteCI
Reviewed-by: glittershark <grfn@gws.fyi>
Diffstat (limited to 'third_party/nix/src/nix-daemon/nix-daemon-proto.cc')
-rw-r--r--third_party/nix/src/nix-daemon/nix-daemon-proto.cc49
1 files changed, 47 insertions, 2 deletions
diff --git a/third_party/nix/src/nix-daemon/nix-daemon-proto.cc b/third_party/nix/src/nix-daemon/nix-daemon-proto.cc
index d847ebff758b..511058c3e25d 100644
--- a/third_party/nix/src/nix-daemon/nix-daemon-proto.cc
+++ b/third_party/nix/src/nix-daemon/nix-daemon-proto.cc
@@ -6,6 +6,7 @@ namespace nix::daemon {
 
 using ::grpc::Status;
 using ::nix::proto::StorePath;
+using ::nix::proto::StorePaths;
 using ::nix::proto::Worker;
 
 class WorkerServiceImpl final : public Worker::Service {
@@ -13,7 +14,7 @@ class WorkerServiceImpl final : public Worker::Service {
   WorkerServiceImpl(nix::Store* store) : store_(store) {}
 
   Status IsValidPath(grpc::ServerContext* context, const StorePath* request,
-                     nix::proto::IsValidPathResponse* response) {
+                     nix::proto::IsValidPathResponse* response) override {
     const auto& path = request->path();
     store_->assertStorePath(path);
     response->set_is_valid(store_->isValidPath(path));
@@ -22,7 +23,7 @@ class WorkerServiceImpl final : public Worker::Service {
   }
 
   Status HasSubstitutes(grpc::ServerContext* context, const StorePath* request,
-                        nix::proto::HasSubstitutesResponse* response) {
+                        nix::proto::HasSubstitutesResponse* response) override {
     const auto& path = request->path();
     store_->assertStorePath(path);
     PathSet res = store_->querySubstitutablePaths({path});
@@ -31,6 +32,50 @@ class WorkerServiceImpl final : public Worker::Service {
     return Status::OK;
   }
 
+  Status QueryReferrers(grpc::ServerContext* context, const StorePath* request,
+                        StorePaths* response) override {
+    const auto& path = request->path();
+    store_->assertStorePath(path);
+
+    PathSet paths;
+    store_->queryReferrers(path, paths);
+
+    for (const auto& path : paths) {
+      response->add_paths(path);
+    }
+
+    return Status::OK;
+  }
+
+  Status QueryValidDerivers(grpc::ServerContext* context,
+                            const StorePath* request, StorePaths* response) {
+    const auto& path = request->path();
+    store_->assertStorePath(path);
+
+    PathSet paths = store_->queryValidDerivers(path);
+
+    for (const auto& path : paths) {
+      response->add_paths(path);
+    }
+
+    return Status::OK;
+  }
+
+  Status QueryDerivationOutputs(grpc::ServerContext* context,
+                                const StorePath* request,
+                                StorePaths* response) override {
+    const auto& path = request->path();
+    store_->assertStorePath(path);
+
+    PathSet paths = store_->queryDerivationOutputs(path);
+
+    for (const auto& path : paths) {
+      response->add_paths(path);
+    }
+
+    return Status::OK;
+  }
+
  private:
   // TODO(tazjin): Who owns the store?
   nix::Store* store_;