From b3c863abc09f9f81150e21af2cc89d75bee98db2 Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Tue, 17 Dec 2024 18:27:37 +0100 Subject: Move functionality for staging from CAS to output paths to TreeReader ...and employ it in LocalApi. --- src/buildtool/execution_api/common/tree_reader.hpp | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/buildtool/execution_api/common/tree_reader.hpp') diff --git a/src/buildtool/execution_api/common/tree_reader.hpp b/src/buildtool/execution_api/common/tree_reader.hpp index 7ec66163..42bf20e6 100644 --- a/src/buildtool/execution_api/common/tree_reader.hpp +++ b/src/buildtool/execution_api/common/tree_reader.hpp @@ -15,6 +15,7 @@ #ifndef INCLUDED_SRC_BUILDTOOL_EXECUTION_API_COMMON_TREE_READER_HPP #define INCLUDED_SRC_BUILDTOOL_EXECUTION_API_COMMON_TREE_READER_HPP +#include #include #include #include @@ -107,6 +108,32 @@ class TreeReader final { } } + /// \brief Traverse a tree recursively and stage all artifacts to paths. + /// \param infos Infos to be staged + /// \param outputs Paths to be used for staging + /// \return True if outputs contain corresponding infos. + [[nodiscard]] auto StageTo(std::vector const& infos, + std::vector const& + outputs) const noexcept -> bool { + if (infos.size() != outputs.size()) { + return false; + } + + for (std::size_t i = 0; i < infos.size(); ++i) { + auto const& info = infos[i]; + if (IsTreeObject(info.type)) { + auto result = RecursivelyReadTreeLeafs(info.digest, outputs[i]); + if (not result or not StageTo(result->infos, result->paths)) { + return false; + } + } + else if (not impl_.StageBlobTo(info, outputs[i])) { + return false; + } + } + return true; + } + private: TImpl impl_; -- cgit v1.2.3