diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2025-02-25 13:42:22 +0100 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2025-02-27 09:03:30 +0100 |
commit | 461312b57d3b49f92861d2c6c5e8a6b13ffa839b (patch) | |
tree | c642cd0d3379e6886d1b3847d38661e249e75d58 /src/buildtool/execution_api/remote/bazel | |
parent | eccc7dcfb22fb9c6c42bbcd5566cd044acd1a2f3 (diff) | |
download | justbuild-461312b57d3b49f92861d2c6c5e8a6b13ffa839b.tar.gz |
ArtifactBlob: Use static function for construction
Diffstat (limited to 'src/buildtool/execution_api/remote/bazel')
3 files changed, 26 insertions, 12 deletions
diff --git a/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp b/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp index dd4ec919..a02b8d4c 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp @@ -36,6 +36,7 @@ #include "src/buildtool/file_system/object_type.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/utils/cpp/back_map.hpp" +#include "src/utils/cpp/expected.hpp" namespace { @@ -302,12 +303,19 @@ auto BazelCasClient::BatchReadBlobs( std::vector<ArtifactBlob>* v, bazel_re::BatchReadBlobsResponse_Response const& r) { - if (auto value = - back_map->GetReference(r.digest())) { - v->emplace_back(*value.value(), - r.data(), - /*is_exec=*/false); + auto ref = back_map->GetReference(r.digest()); + if (not ref.has_value()) { + return; } + auto blob = ArtifactBlob::FromMemory( + HashFunction{ref.value()->GetHashType()}, + ref.value()->IsTree() ? ObjectType::Tree + : ObjectType::File, + r.data()); + if (not blob.has_value()) { + return; + } + v->emplace_back(*std::move(blob)); }); if (batch_response.ok) { std::move(batch_response.result.begin(), diff --git a/src/buildtool/execution_api/remote/bazel/bazel_response.cpp b/src/buildtool/execution_api/remote/bazel/bazel_response.cpp index f06a4275..d0429cd7 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_response.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_response.cpp @@ -50,12 +50,8 @@ auto ProcessDirectoryMessage(HashFunction hash_function, fmt::format("found invalid symlink at {}", link.name())}; } } - auto data = dir.SerializeAsString(); - auto digest = ArtifactDigestFactory::HashDataAs<ObjectType::File>( - hash_function, data); - return ArtifactBlob{std::move(digest), - std::move(data), - /*is_exec=*/false}; + return ArtifactBlob::FromMemory( + hash_function, ObjectType::File, dir.SerializeAsString()); } } // namespace diff --git a/src/buildtool/execution_api/remote/bazel/bytestream_client.hpp b/src/buildtool/execution_api/remote/bazel/bytestream_client.hpp index 23a296c9..cf85b769 100644 --- a/src/buildtool/execution_api/remote/bazel/bytestream_client.hpp +++ b/src/buildtool/execution_api/remote/bazel/bytestream_client.hpp @@ -33,8 +33,10 @@ #include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/common/remote/client_common.hpp" #include "src/buildtool/common/remote/port.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/common/bytestream_utils.hpp" #include "src/buildtool/execution_api/common/ids.hpp" +#include "src/buildtool/file_system/object_type.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/logger.hpp" #include "src/utils/cpp/expected.hpp" @@ -115,7 +117,15 @@ class ByteStreamClient { if (not data) { return std::nullopt; } - return ArtifactBlob{digest, std::move(output), /*is_exec=*/false}; + + auto blob = ArtifactBlob::FromMemory( + HashFunction{digest.GetHashType()}, + digest.IsTree() ? ObjectType::Tree : ObjectType::File, + std::move(output)); + if (not blob.has_value() or blob->GetDigest() != digest) { + return std::nullopt; + } + return *std::move(blob); } [[nodiscard]] auto Write(std::string const& instance_name, |