diff options
author | Sascha Roloff <sascha.roloff@huawei.com> | 2022-07-05 20:29:24 +0200 |
---|---|---|
committer | Sascha Roloff <sascha.roloff@huawei.com> | 2022-08-05 14:41:31 +0200 |
commit | da3064fd8dcffe1cae321bf1f000c07f4f7d4766 (patch) | |
tree | 1b3beca3e757b42e48a34ce664025d34be7bacaf | |
parent | 4ce6ec5563c0aa277b455c9c1ded7e8556402c68 (diff) | |
download | justbuild-da3064fd8dcffe1cae321bf1f000c07f4f7d4766.tar.gz |
Directory entries can detect themselves as known trees and return according description
-rw-r--r-- | src/buildtool/file_system/file_root.hpp | 23 |
1 files changed, 23 insertions, 0 deletions
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<ArtifactDescription> { + if (Compatibility::IsCompatible()) { + return std::nullopt; + } + if (std::holds_alternative<tree_t>(data_)) { + try { + auto const& data = std::get<tree_t>(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<pairs_t>(data_)) { auto const& data = std::get<pairs_t>(data_); |