From 461312b57d3b49f92861d2c6c5e8a6b13ffa839b Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Tue, 25 Feb 2025 13:42:22 +0100 Subject: ArtifactBlob: Use static function for construction --- .../execution_engine/executor/executor.hpp | 35 ++++++++++++++-------- 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'src/buildtool/execution_engine/executor/executor.hpp') diff --git a/src/buildtool/execution_engine/executor/executor.hpp b/src/buildtool/execution_engine/executor/executor.hpp index eea0336d..93cb9655 100644 --- a/src/buildtool/execution_engine/executor/executor.hpp +++ b/src/buildtool/execution_engine/executor/executor.hpp @@ -331,6 +331,7 @@ class ExecutorImpl { } // upload missing entries (blobs or trees) + HashFunction const hash_function{api.GetHashType()}; std::unordered_set container; for (auto const& [digest, value] : missing_entries) { auto const entry = value->second; @@ -338,13 +339,16 @@ class ExecutorImpl { if (not content.has_value()) { return false; } + auto blob = ArtifactBlob::FromMemory( + hash_function, entry->Type(), *std::move(content)); + if (not blob.has_value()) { + return false; + } // store and/or upload blob, taking into account the maximum // transfer size if (not UpdateContainerAndUpload( &container, - ArtifactBlob{*digest, - std::move(*content), - IsExecutableObject(entry->Type())}, + *std::move(blob), /*exception_is_fatal=*/true, [&api](std::unordered_set&& blobs) { return api.Upload(std::move(blobs), @@ -396,9 +400,14 @@ class ExecutorImpl { return false; } - return api.Upload({ArtifactBlob{info.digest, - std::move(*content), - IsExecutableObject(info.type)}}, + auto blob = ArtifactBlob::FromMemory( + HashFunction{api.GetHashType()}, info.type, *std::move(content)); + if (not blob.has_value()) { + Logger::Log(LogLevel::Error, "failed to create ArtifactBlob"); + return false; + } + + return api.Upload({*std::move(blob)}, /*skip_find_missing=*/true); } @@ -483,12 +492,14 @@ class ExecutorImpl { if (not content.has_value()) { return std::nullopt; } - HashFunction const hash_function{api.GetHashType()}; - auto digest = ArtifactDigestFactory::HashDataAs( - hash_function, *content); - if (not api.Upload({ArtifactBlob{digest, - std::move(*content), - IsExecutableObject(*object_type)}})) { + + auto blob = ArtifactBlob::FromMemory( + HashFunction{api.GetHashType()}, *object_type, *std::move(content)); + if (not blob.has_value()) { + return std::nullopt; + } + auto digest = blob->GetDigest(); + if (not api.Upload({*std::move(blob)})) { return std::nullopt; } return Artifact::ObjectInfo{.digest = std::move(digest), -- cgit v1.2.3