From da3064fd8dcffe1cae321bf1f000c07f4f7d4766 Mon Sep 17 00:00:00 2001 From: Sascha Roloff Date: Tue, 5 Jul 2022 20:29:24 +0200 Subject: Directory entries can detect themselves as known trees and return according description --- src/buildtool/file_system/file_root.hpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/buildtool/file_system/file_root.hpp') diff --git a/src/buildtool/file_system/file_root.hpp b/src/buildtool/file_system/file_root.hpp index 872ae1ff..10b04c66 100644 --- a/src/buildtool/file_system/file_root.hpp +++ b/src/buildtool/file_system/file_root.hpp @@ -196,6 +196,29 @@ class FileRoot { return true; } + [[nodiscard]] auto AsKnownTree(std::string const& repository) + const noexcept -> std::optional { + if (Compatibility::IsCompatible()) { + return std::nullopt; + } + if (std::holds_alternative(data_)) { + try { + auto const& data = std::get(data_); + auto const& id = data->Hash(); + auto const& size = data->Size(); + if (size) { + return ArtifactDescription{ + ArtifactDigest{id, *size, /*is_tree=*/true}, + ObjectType::Tree, + repository}; + } + } catch (...) { + return std::nullopt; + } + } + return std::nullopt; + } + [[nodiscard]] auto FilesIterator() const -> Iterator { if (std::holds_alternative(data_)) { auto const& data = std::get(data_); -- cgit v1.2.3