diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-01-24 17:09:01 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-01-31 17:15:46 +0100 |
commit | 66df7f4956c6fe1823eb43d31c3cbac7d8716125 (patch) | |
tree | 3f8bf106b3e189eeb4cfa01f97e8f9bb18678406 /src/buildtool/serve_api/remote/source_tree_client.hpp | |
parent | 3dc81b4b5a89f4e37af45ec9954723c79c3017cf (diff) | |
download | justbuild-66df7f4956c6fe1823eb43d31c3cbac7d8716125.tar.gz |
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.
Diffstat (limited to 'src/buildtool/serve_api/remote/source_tree_client.hpp')
-rw-r--r-- | src/buildtool/serve_api/remote/source_tree_client.hpp | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/src/buildtool/serve_api/remote/source_tree_client.hpp b/src/buildtool/serve_api/remote/source_tree_client.hpp index 3ea1058b..24b2654a 100644 --- a/src/buildtool/serve_api/remote/source_tree_client.hpp +++ b/src/buildtool/serve_api/remote/source_tree_client.hpp @@ -17,6 +17,7 @@ #include <memory> #include <string> +#include <variant> #include "justbuild/just_serve/just_serve.grpc.pb.h" #include "src/buildtool/common/remote/port.hpp" @@ -29,42 +30,54 @@ class SourceTreeClient { public: SourceTreeClient(std::string const& server, Port port) noexcept; - /// \brief Retrieve the Git tree of a given commit, if known by the remote. + // An error + data union type + using result_t = std::variant<bool, std::string>; + + /// \brief Retrieve the Git tree of a given commit, if known by the + /// endpoint. It is a fatal error if the commit is known to the endpoint but + /// no tree is able to be returned. /// \param[in] commit_id Hash of the Git commit to look up. /// \param[in] subdir Relative path of the tree inside commit. /// \param[in] sync_tree Sync tree to the remote-execution endpoint. - /// \returns The hash of the tree if commit found, nullopt otherwise. + /// \returns An error + data union, where at index 0 we return a fatal flag, + /// with false meaning non-fatal failure (commit or subtree not found), and + /// at index 1 the tree identifier on success. [[nodiscard]] auto ServeCommitTree(std::string const& commit_id, std::string const& subdir, - bool sync_tree) - -> std::optional<std::string>; + bool sync_tree) -> result_t; - /// \brief Retrieve the Git tree of an archive content, if known by remote. + /// \brief Retrieve the Git tree of an archive content, if known by the + /// endpoint. It is a fatal error if the content blob is known to the + /// endpoint but no tree is able to be returned. /// \param[in] content Hash of the archive content to look up. /// \param[in] archive_type Type of archive ("archive"|"zip"). /// \param[in] subdir Relative path of the tree inside archive. /// \param[in] resolve_symlinks Optional enum to state how symlinks in the /// archive should be handled if the tree has to be actually computed. /// \param[in] sync_tree Sync tree to the remote-execution endpoint. - /// \returns The hash of the tree if content blob found, nullopt otherwise. + /// \returns An error + data union, where at index 0 we return a fatal flag, + /// with false meaning non-fatal failure (content blob not found), and at + /// index 1 the tree identifier on success. [[nodiscard]] auto ServeArchiveTree( std::string const& content, std::string const& archive_type, std::string const& subdir, std::optional<PragmaSpecial> const& resolve_symlinks, - bool sync_tree) -> std::optional<std::string>; + bool sync_tree) -> result_t; /// \brief Retrieve the Git tree of a directory of distfiles, if all the - /// content blobs are known by serve remote. + /// content blobs are known by the endpoint. It is a fatal error if all + /// content blobs are known but no tree is able to be returned. /// \param[in] distfiles Mapping from distfile names to content blob ids. /// \param[in] sync_tree Sync tree and all ditfile blobs to the /// remote-execution endpoint. - /// \returns The hash of the resulting tree if all distfile blobs found, - /// nullopt otherwise. + /// \returns An error + data union, where at index 0 we return a fatal flag, + /// with false meaning non-fatal failure (at least one distfile blob + /// missing), and at index 1 the tree identifier on success. [[nodiscard]] auto ServeDistdirTree( std::shared_ptr<std::unordered_map<std::string, std::string>> const& distfiles, - bool sync_tree) -> std::optional<std::string>; + bool sync_tree) -> result_t; /// \brief Make a given content blob available in remote CAS, if known by /// serve remote. |