diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/storage/large_object_cas.tpp | 15 | ||||
-rw-r--r-- | src/buildtool/storage/local_ac.tpp | 11 | ||||
-rw-r--r-- | src/buildtool/storage/local_cas.tpp | 37 |
3 files changed, 43 insertions, 20 deletions
diff --git a/src/buildtool/storage/large_object_cas.tpp b/src/buildtool/storage/large_object_cas.tpp index 18c15ce6..67a4ad75 100644 --- a/src/buildtool/storage/large_object_cas.tpp +++ b/src/buildtool/storage/large_object_cas.tpp @@ -22,7 +22,9 @@ #include "fmt/core.h" #include "nlohmann/json.hpp" +#include "src/buildtool/common/artifact_digest_factory.hpp" #include "src/buildtool/compatibility/compatibility.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/storage/file_chunker.hpp" #include "src/buildtool/storage/large_object_cas.hpp" @@ -71,11 +73,18 @@ auto LargeObjectCAS<kDoGlobalUplink, kType>::ReadEntry( nlohmann::json j = nlohmann::json::parse(stream); parts.reserve(j.size()); + auto const hash_type = local_cas_.GetHashFunction().GetType(); for (auto const& j_part : j) { - auto hash = j_part.at(kHashIndex).template get<std::string>(); - auto size = j_part.at(kSizeIndex).template get<std::size_t>(); + auto digest = ArtifactDigestFactory::Create( + hash_type, + j_part.at(kHashIndex).template get<std::string>(), + j_part.at(kSizeIndex).template get<std::size_t>(), + /*is_tree=*/false); + if (not digest) { + return std::nullopt; + } - parts.emplace_back(std::move(hash), size, /*is_tree=*/false); + parts.emplace_back(*std::move(digest)); } } catch (...) { return std::nullopt; diff --git a/src/buildtool/storage/local_ac.tpp b/src/buildtool/storage/local_ac.tpp index e58c7fb9..d5cbbe5e 100644 --- a/src/buildtool/storage/local_ac.tpp +++ b/src/buildtool/storage/local_ac.tpp @@ -155,17 +155,16 @@ auto LocalAC<kDoGlobalUplink>::ReadActionKey(ArtifactDigest const& action_id) fmt::format("Cache miss, entry not found {}", key_path.string())}; } - std::optional<ArtifactDigest> action_key; try { - nlohmann::json j = nlohmann::json::parse(*key_content); - action_key = ArtifactDigest{j[0].template get<std::string>(), - j[1].template get<std::size_t>(), - /*is_tree=*/false}; + nlohmann::json const j = nlohmann::json::parse(*key_content); + return ArtifactDigestFactory::Create(cas_.GetHashFunction().GetType(), + j[0].template get<std::string>(), + j[1].template get<std::size_t>(), + /*is_tree=*/false); } catch (...) { return unexpected{fmt::format( "Parsing cache entry failed for action {}", action_id.hash())}; } - return *std::move(action_key); } template <bool kDoGlobalUplink> diff --git a/src/buildtool/storage/local_cas.tpp b/src/buildtool/storage/local_cas.tpp index 8b91f7e4..7ab29b08 100644 --- a/src/buildtool/storage/local_cas.tpp +++ b/src/buildtool/storage/local_cas.tpp @@ -152,15 +152,21 @@ auto LocalCAS<kDoGlobalUplink>::LocalUplinkGitTree( // names. auto const entry_type = entry_vector.front().type; auto const digest = - ArtifactDigest{ToHexString(raw_id), 0, IsTreeObject(entry_type)}; - if (digest.IsTree()) { - if (not LocalUplinkGitTree(latest, digest)) { + ArtifactDigestFactory::Create(hash_function_.GetType(), + ToHexString(raw_id), + 0, + IsTreeObject(entry_type)); + if (not digest) { + return false; + } + if (digest->IsTree()) { + if (not LocalUplinkGitTree(latest, *digest)) { return false; } } else { if (not LocalUplinkBlob( - latest, digest, IsExecutableObject(entry_type))) { + latest, *digest, IsExecutableObject(entry_type))) { return false; } } @@ -316,23 +322,32 @@ auto LocalCAS<kDoGlobalUplink>::CheckTreeInvariant( // Ensure all entries are in the storage: for (const auto& entry : *entries) { for (auto const& item : entry.second) { - auto const digest = ArtifactDigest(ToHexString(entry.first), - /*size_unknown=*/0ULL, - IsTreeObject(item.type)); + auto const digest = + ArtifactDigestFactory::Create(hash_function_.GetType(), + ToHexString(entry.first), + /*size_unknown=*/0, + IsTreeObject(item.type)); + if (not digest) { + return LargeObjectError{ + LargeObjectErrorCode::InvalidTree, + fmt::format("tree invariant violated {}:\n {}", + tree_digest.hash(), + digest.error())}; + } // To avoid splicing during search, large CASes are inspected first. bool const entry_exists = IsTreeObject(item.type) - ? cas_tree_large_.GetEntryPath(digest) or TreePath(digest) - : cas_file_large_.GetEntryPath(digest) or - BlobPath(digest, IsExecutableObject(item.type)); + ? cas_tree_large_.GetEntryPath(*digest) or TreePath(*digest) + : cas_file_large_.GetEntryPath(*digest) or + BlobPath(*digest, IsExecutableObject(item.type)); if (not entry_exists) { return LargeObjectError{ LargeObjectErrorCode::InvalidTree, fmt::format("tree invariant violated {} : missing part {}", tree_digest.hash(), - digest.hash())}; + digest->hash())}; } } } |