diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/storage/local_cas.hpp | 16 | ||||
-rw-r--r-- | src/buildtool/storage/local_cas.tpp | 23 |
2 files changed, 31 insertions, 8 deletions
diff --git a/src/buildtool/storage/local_cas.hpp b/src/buildtool/storage/local_cas.hpp index ee5a6ea2..8a95c234 100644 --- a/src/buildtool/storage/local_cas.hpp +++ b/src/buildtool/storage/local_cas.hpp @@ -213,6 +213,14 @@ class LocalCAS { std::string const& tree_data) const noexcept -> std::optional<LargeObjectError>; + /// \brief Check whether all parts of the tree are in the storage. + /// \param tree_digest Digest of the tree to be checked. + /// \param file Content of the tree. + /// \return An error on fail. + [[nodiscard]] auto CheckTreeInvariant(ArtifactDigest const& tree_digest, + std::filesystem::path const& file) + const noexcept -> std::optional<LargeObjectError>; + /// \brief Uplink blob from this generation to latest LocalCAS generation. /// Performs a synchronization if requested and if blob is only available /// with inverse x-bit. This function is only available for instances that @@ -355,6 +363,14 @@ auto LocalCAS<kDoGlobalUplink>::CheckTreeInvariant( } template <bool kDoGlobalUplink> +auto LocalCAS<kDoGlobalUplink>::CheckTreeInvariant( + ArtifactDigest const& tree_digest, + std::filesystem::path const& file) const noexcept + -> std::optional<LargeObjectError> { + return std::nullopt; +} + +template <bool kDoGlobalUplink> template <ObjectType kType> auto LocalCAS<kDoGlobalUplink>::Splice(ArtifactDigest const& digest, std::vector<ArtifactDigest> const& parts) diff --git a/src/buildtool/storage/local_cas.tpp b/src/buildtool/storage/local_cas.tpp index a7f81b1a..e47cffa4 100644 --- a/src/buildtool/storage/local_cas.tpp +++ b/src/buildtool/storage/local_cas.tpp @@ -355,6 +355,20 @@ auto LocalCAS<kDoGlobalUplink>::CheckTreeInvariant( } template <bool kDoGlobalUplink> +auto LocalCAS<kDoGlobalUplink>::CheckTreeInvariant( + ArtifactDigest const& tree_digest, + std::filesystem::path const& file) const noexcept + -> std::optional<LargeObjectError> { + auto const tree_data = FileSystemManager::ReadFile(file); + if (not tree_data) { + return LargeObjectError{ + LargeObjectErrorCode::Internal, + fmt::format("could not read tree {}", tree_digest.hash())}; + } + return CheckTreeInvariant(tree_digest, *tree_data); +} + +template <bool kDoGlobalUplink> template <ObjectType kType> auto LocalCAS<kDoGlobalUplink>::Splice(ArtifactDigest const& digest, std::vector<ArtifactDigest> const& parts) @@ -400,14 +414,7 @@ auto LocalCAS<kDoGlobalUplink>::Splice(ArtifactDigest const& digest, // Check tree invariants: if constexpr (kIsTree) { if (ProtocolTraits::IsNative(hash_function_.GetType())) { - // Read tree entries: - auto const tree_data = FileSystemManager::ReadFile(file_path); - if (not tree_data) { - return unexpected{LargeObjectError{ - LargeObjectErrorCode::Internal, - fmt::format("could not read tree {}", digest.hash())}}; - } - if (auto error = CheckTreeInvariant(digest, *tree_data)) { + if (auto error = CheckTreeInvariant(digest, file_path)) { return unexpected{std::move(*error)}; } } |