From 661353f2006a46216fe1a7fa2ae5abd08d540f49 Mon Sep 17 00:00:00 2001 From: Kane York Date: Mon, 3 Aug 2020 08:18:56 -0700 Subject: chore(3p/nix/daemon): replace all assertStorePath with a macro Two exceptions: IsValidPath needs to return success for invalid paths, and QueryAllValidPaths shouldn't need to check the paths it gets from itself. Change-Id: I4d9d4125d34e8de42f30070aec607f8a902eded7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1598 Tested-by: BuildkiteCI Reviewed-by: glittershark --- third_party/nix/src/nix-daemon/nix-daemon-proto.cc | 34 +++++++++++++--------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'third_party') 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 bf65dd315d00..01a022a30893 100644 --- a/third_party/nix/src/nix-daemon/nix-daemon-proto.cc +++ b/third_party/nix/src/nix-daemon/nix-daemon-proto.cc @@ -2,6 +2,7 @@ #include +#include #include #include #include @@ -83,6 +84,12 @@ struct RetrieveRegularNARSink : ParseSink { } }; +#define ASSERT_INPUT_STORE_PATH(path) \ + if (!store_->isStorePath(path)) { \ + return Status(grpc::StatusCode::INVALID_ARGUMENT, \ + absl::StrFormat("path '%s' is not in the Nix store", path)); \ + } + class WorkerServiceImpl final : public WorkerService::Service { public: WorkerServiceImpl(nix::Store& store) : store_(&store) {} @@ -90,7 +97,6 @@ class WorkerServiceImpl final : public WorkerService::Service { Status IsValidPath(grpc::ServerContext* context, const StorePath* request, nix::proto::IsValidPathResponse* response) override { const auto& path = request->path(); - store_->assertStorePath(path); response->set_is_valid(store_->isValidPath(path)); return Status::OK; @@ -99,7 +105,7 @@ class WorkerServiceImpl final : public WorkerService::Service { Status HasSubstitutes(grpc::ServerContext* context, const StorePath* request, nix::proto::HasSubstitutesResponse* response) override { const auto& path = request->path(); - store_->assertStorePath(path); + ASSERT_INPUT_STORE_PATH(path); PathSet res = store_->querySubstitutablePaths({path}); response->set_has_substitutes(res.find(path) != res.end()); @@ -109,7 +115,7 @@ class WorkerServiceImpl final : public WorkerService::Service { Status QueryReferrers(grpc::ServerContext* context, const StorePath* request, StorePaths* response) override { const auto& path = request->path(); - store_->assertStorePath(path); + ASSERT_INPUT_STORE_PATH(path); PathSet paths; store_->queryReferrers(path, paths); @@ -233,7 +239,7 @@ class WorkerServiceImpl final : public WorkerService::Service { const StorePath* request, StorePaths* response) override { const auto& path = request->path(); - store_->assertStorePath(path); + ASSERT_INPUT_STORE_PATH(path); PathSet paths = store_->queryValidDerivers(path); @@ -248,7 +254,7 @@ class WorkerServiceImpl final : public WorkerService::Service { const StorePath* request, StorePaths* response) override { const auto& path = request->path(); - store_->assertStorePath(path); + ASSERT_INPUT_STORE_PATH(path); PathSet paths = store_->queryDerivationOutputs(path); @@ -264,7 +270,6 @@ class WorkerServiceImpl final : public WorkerService::Service { StorePaths* response) override { const auto paths = store_->queryAllValidPaths(); for (const auto& path : paths) { - store_->assertStorePath(path); response->add_paths(path); } @@ -274,7 +279,8 @@ class WorkerServiceImpl final : public WorkerService::Service { Status QueryPathInfo(grpc::ServerContext* context, const StorePath* request, PathInfo* response) override { auto path = request->path(); - store_->assertStorePath(path); + ASSERT_INPUT_STORE_PATH(path); + response->mutable_path()->set_path(path); try { auto info = store_->queryPathInfo(path); @@ -310,7 +316,7 @@ class WorkerServiceImpl final : public WorkerService::Service { grpc::ServerContext* context, const StorePath* request, nix::proto::DerivationOutputNames* response) override { auto path = request->path(); - store_->assertStorePath(path); + ASSERT_INPUT_STORE_PATH(path); auto names = store_->queryDerivationOutputNames(path); for (const auto& name : names) { response->add_names(name); @@ -324,7 +330,7 @@ class WorkerServiceImpl final : public WorkerService::Service { StorePath* response) override { auto hash_part = request->hash_part(); auto path = store_->queryPathFromHashPart(hash_part); - store_->assertStorePath(path); + ASSERT_INPUT_STORE_PATH(path); response->set_path(path); return Status::OK; } @@ -334,7 +340,7 @@ class WorkerServiceImpl final : public WorkerService::Service { StorePaths* response) override { std::set paths; for (const auto& path : request->paths()) { - store_->assertStorePath(path); + ASSERT_INPUT_STORE_PATH(path); paths.insert(path); } @@ -352,7 +358,7 @@ class WorkerServiceImpl final : public WorkerService::Service { StorePaths* response) override { std::set paths; for (const auto& path : request->paths()) { - store_->assertStorePath(path); + ASSERT_INPUT_STORE_PATH(path); paths.insert(path); } @@ -388,7 +394,7 @@ class WorkerServiceImpl final : public WorkerService::Service { const nix::proto::BuildDerivationRequest* request, nix::proto::BuildDerivationResponse* response) override { auto drv_path = request->drv_path().path(); - store_->assertStorePath(drv_path); + ASSERT_INPUT_STORE_PATH(drv_path); auto drv = BasicDerivation::from_proto(&request->derivation(), *store_); auto build_mode = nix::BuildModeFrom(request->build_mode()); @@ -408,7 +414,7 @@ class WorkerServiceImpl final : public WorkerService::Service { const nix::proto::AddSignaturesRequest* request, google::protobuf::Empty* response) override { auto path = request->path().path(); - store_->assertStorePath(path); + ASSERT_INPUT_STORE_PATH(path); StringSet sigs; sigs.insert(request->sigs().sigs().begin(), request->sigs().sigs().end()); @@ -422,7 +428,7 @@ class WorkerServiceImpl final : public WorkerService::Service { nix::proto::QueryMissingResponse* response) override { std::set targets; for (auto& path : request->paths()) { - store_->assertStorePath(path); + ASSERT_INPUT_STORE_PATH(path); targets.insert(path); } PathSet will_build; -- cgit 1.4.1