about summary refs log tree commit diff
path: root/third_party/nix/src/libstore/rpc-store.cc
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2020-08-01T14·59-0400
committerglittershark <grfn@gws.fyi>2020-08-01T19·00+0000
commit3fdce7c6be52bd2b86bd8a75c06f27f94b753c4f (patch)
tree20e1c32bafe71c434dbd796f86e13c4d088ac061 /third_party/nix/src/libstore/rpc-store.cc
parentee48e830e67ff53097f76ee2bde9ff60caf0dce7 (diff)
feat(3p/nix): Implement a few more RPC calls r/1529
Implement the RPC client calls for QueryPathFromHashPart,
QuerySubstitutablePaths, and QuerySubstitutablePathInfos, and the
handler for QuerySubstitutablePathInfos.

Refs: #29
Change-Id: Idf383b771f159f267d8f65367bc4af3d239e32b7
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1515
Tested-by: BuildkiteCI
Reviewed-by: kanepyork <rikingcoding@gmail.com>
Diffstat (limited to 'third_party/nix/src/libstore/rpc-store.cc')
-rw-r--r--third_party/nix/src/libstore/rpc-store.cc35
1 files changed, 32 insertions, 3 deletions
diff --git a/third_party/nix/src/libstore/rpc-store.cc b/third_party/nix/src/libstore/rpc-store.cc
index e2eb240f8b8a..d1687473c17e 100644
--- a/third_party/nix/src/libstore/rpc-store.cc
+++ b/third_party/nix/src/libstore/rpc-store.cc
@@ -38,6 +38,14 @@ proto::StorePath StorePath(const Path& path) {
   return store_path;
 }
 
+proto::StorePaths StorePaths(const PathSet& paths) {
+  proto::StorePaths result;
+  for (const auto& path : paths) {
+    result.add_paths(path);
+  }
+  return result;
+}
+
 template <typename T, typename U>
 T FillFrom(const U& src) {
   T result;
@@ -143,16 +151,37 @@ StringSet RpcStore::queryDerivationOutputNames(const Path& path) {
 }
 
 Path RpcStore::queryPathFromHashPart(const std::string& hashPart) {
-  throw absl::StrCat("Not implemented ", __func__);
+  proto::StorePath path;
+  proto::HashPart proto_hash_part;
+  proto_hash_part.set_hash_part(hashPart);
+  SuccessOrThrow(stub_->QueryPathFromHashPart(&ctx, proto_hash_part, &path));
+  return path.path();
 }
 
 PathSet RpcStore::querySubstitutablePaths(const PathSet& paths) {
-  throw absl::StrCat("Not implemented ", __func__);
+  proto::StorePaths result;
+  SuccessOrThrow(
+      stub_->QuerySubstitutablePaths(&ctx, StorePaths(paths), &result));
+  return FillFrom<PathSet>(result.paths());
 }
 
 void RpcStore::querySubstitutablePathInfos(const PathSet& paths,
                                            SubstitutablePathInfos& infos) {
-  throw absl::StrCat("Not implemented ", __func__);
+  proto::SubstitutablePathInfos result;
+  SuccessOrThrow(
+      stub_->QuerySubstitutablePathInfos(&ctx, StorePaths(paths), &result));
+
+  for (const auto& path_info : result.path_infos()) {
+    auto path = path_info.path().path();
+    SubstitutablePathInfo& info(infos[path]);
+    info.deriver = path_info.deriver().path();
+    if (!info.deriver.empty()) {
+      assertStorePath(info.deriver);
+    }
+    info.references = FillFrom<PathSet>(path_info.references());
+    info.downloadSize = path_info.download_size();
+    info.narSize = path_info.nar_size();
+  }
 }
 
 void RpcStore::addToStore(const ValidPathInfo& info, Source& narSource,