From 66df7f4956c6fe1823eb43d31c3cbac7d8716125 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Wed, 24 Jan 2024 17:09:01 +0100 Subject: just-mr: Failure in serve api root tree requests should be fatal The requests to retrieve the tree of a commit, archive, or distdir also set up those trees in a way that the serve endpoint can later build against them, besides allowing just-mr to set up roots locally. Therefore, if the witnessing entity (Git commit, content blob, or distdir, respectively) is known to the serve endpoint, then failing to set up the root tree there should result in a failure also of the just-mr setup on the client side. --- .../serve_api/remote/source_tree_client.cpp | 31 +++++++++++++--------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'src/buildtool/serve_api/remote/source_tree_client.cpp') diff --git a/src/buildtool/serve_api/remote/source_tree_client.cpp b/src/buildtool/serve_api/remote/source_tree_client.cpp index 073181a0..8267df7f 100644 --- a/src/buildtool/serve_api/remote/source_tree_client.cpp +++ b/src/buildtool/serve_api/remote/source_tree_client.cpp @@ -64,8 +64,7 @@ SourceTreeClient::SourceTreeClient(std::string const& server, auto SourceTreeClient::ServeCommitTree(std::string const& commit_id, std::string const& subdir, - bool sync_tree) - -> std::optional { + bool sync_tree) -> result_t { justbuild::just_serve::ServeCommitTreeRequest request{}; request.set_commit(commit_id); request.set_subdir(subdir); @@ -77,16 +76,18 @@ auto SourceTreeClient::ServeCommitTree(std::string const& commit_id, if (not status.ok()) { LogStatus(&logger_, LogLevel::Debug, status); - return std::nullopt; + return true; // fatal failure } if (response.status() != ::justbuild::just_serve::ServeCommitTreeResponse::OK) { logger_.Emit(LogLevel::Debug, "ServeCommitTree response returned with {}", static_cast(response.status())); - return std::nullopt; + return /*fatal = */ ( + response.status() != + ::justbuild::just_serve::ServeCommitTreeResponse::NOT_FOUND); } - return response.tree(); + return response.tree(); // success } auto SourceTreeClient::ServeArchiveTree( @@ -94,7 +95,7 @@ auto SourceTreeClient::ServeArchiveTree( std::string const& archive_type, std::string const& subdir, std::optional const& resolve_symlinks, - bool sync_tree) -> std::optional { + bool sync_tree) -> result_t { justbuild::just_serve::ServeArchiveTreeRequest request{}; request.set_content(content); request.set_archive_type(StringToArchiveType(archive_type)); @@ -109,22 +110,24 @@ auto SourceTreeClient::ServeArchiveTree( if (not status.ok()) { LogStatus(&logger_, LogLevel::Debug, status); - return std::nullopt; + return true; // fatal failure } if (response.status() != ::justbuild::just_serve::ServeArchiveTreeResponse::OK) { logger_.Emit(LogLevel::Debug, "ServeArchiveTree response returned with {}", static_cast(response.status())); - return std::nullopt; + return /*fatal = */ ( + response.status() != + ::justbuild::just_serve::ServeArchiveTreeResponse::NOT_FOUND); } - return response.tree(); + return response.tree(); // success } auto SourceTreeClient::ServeDistdirTree( std::shared_ptr> const& distfiles, - bool sync_tree) -> std::optional { + bool sync_tree) -> result_t { justbuild::just_serve::ServeDistdirTreeRequest request{}; for (auto const& [k, v] : *distfiles) { auto* distfile = request.add_distfiles(); @@ -139,16 +142,18 @@ auto SourceTreeClient::ServeDistdirTree( if (not status.ok()) { LogStatus(&logger_, LogLevel::Debug, status); - return std::nullopt; + return true; // fatal failure } if (response.status() != ::justbuild::just_serve::ServeDistdirTreeResponse::OK) { logger_.Emit(LogLevel::Debug, "ServeDistdirTree response returned with {}", static_cast(response.status())); - return std::nullopt; + return /*fatal = */ ( + response.status() != + ::justbuild::just_serve::ServeDistdirTreeResponse::NOT_FOUND); } - return response.tree(); + return response.tree(); // success } auto SourceTreeClient::ServeContent(std::string const& content) -> bool { -- cgit v1.2.3