From 50bcabb0717dae7c8411db59115c41b7cc636cb3 Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Wed, 28 Aug 2024 14:43:23 +0200 Subject: Replace ArtifactDigest::CreateFromFile ...with ArtifactDigestFactory::HashFileAs --- src/buildtool/common/artifact_digest.hpp | 15 --------------- src/buildtool/file_system/TARGETS | 1 + src/buildtool/file_system/object_cas.hpp | 4 +++- src/buildtool/storage/TARGETS | 1 + src/buildtool/storage/compactifier.cpp | 5 +++-- src/buildtool/storage/local_cas.tpp | 3 ++- 6 files changed, 10 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/buildtool/common/artifact_digest.hpp b/src/buildtool/common/artifact_digest.hpp index ebd01ceb..24097776 100644 --- a/src/buildtool/common/artifact_digest.hpp +++ b/src/buildtool/common/artifact_digest.hpp @@ -96,21 +96,6 @@ class ArtifactDigest final { } } - template - [[nodiscard]] static auto CreateFromFile( - HashFunction hash_function, - std::filesystem::path const& path) noexcept - -> std::optional { - static constexpr bool kIsTree = IsTreeObject(kType); - auto const hash = kIsTree ? hash_function.HashTreeFile(path) - : hash_function.HashBlobFile(path); - if (hash) { - return ArtifactDigest{ - hash->first.HexString(), hash->second, kIsTree}; - } - return std::nullopt; - } - private: std::size_t size_{}; std::string hash_{}; diff --git a/src/buildtool/file_system/TARGETS b/src/buildtool/file_system/TARGETS index ef5abada..9d70f7d8 100644 --- a/src/buildtool/file_system/TARGETS +++ b/src/buildtool/file_system/TARGETS @@ -26,6 +26,7 @@ [ "file_storage" , ["src/buildtool/file_system", "file_system_manager"] , ["src/buildtool/common", "common"] + , ["src/buildtool/common", "artifact_digest_factory"] , ["src/buildtool/logging", "log_level"] , ["src/buildtool/logging", "logging"] , ["src/buildtool/crypto", "hash_function"] diff --git a/src/buildtool/file_system/object_cas.hpp b/src/buildtool/file_system/object_cas.hpp index d8ea71a2..79ba70da 100644 --- a/src/buildtool/file_system/object_cas.hpp +++ b/src/buildtool/file_system/object_cas.hpp @@ -23,6 +23,7 @@ #include "gsl/gsl" #include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/common/artifact_digest_factory.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/file_system/file_storage.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" @@ -129,7 +130,8 @@ class ObjectCAS { [[nodiscard]] auto CreateDigest(std::filesystem::path const& file_path) const noexcept -> std::optional { - return ArtifactDigest::CreateFromFile(hash_function_, file_path); + return ArtifactDigestFactory::HashFileAs(hash_function_, + file_path); } [[nodiscard]] auto IsAvailable( diff --git a/src/buildtool/storage/TARGETS b/src/buildtool/storage/TARGETS index c4377581..7ca3f6be 100644 --- a/src/buildtool/storage/TARGETS +++ b/src/buildtool/storage/TARGETS @@ -63,6 +63,7 @@ [ "config" , "file_chunker" , ["src/buildtool/common", "common"] + , ["src/buildtool/common", "artifact_digest_factory"] , ["src/buildtool/file_system", "file_storage"] , ["src/buildtool/file_system", "object_cas"] , ["src/buildtool/execution_api/common", "common"] diff --git a/src/buildtool/storage/compactifier.cpp b/src/buildtool/storage/compactifier.cpp index 1e6033ed..2a6368ca 100644 --- a/src/buildtool/storage/compactifier.cpp +++ b/src/buildtool/storage/compactifier.cpp @@ -22,6 +22,7 @@ #include #include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/common/artifact_digest_factory.hpp" #include "src/buildtool/common/bazel_types.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/crypto/hasher.hpp" @@ -272,8 +273,8 @@ template } // Calculate the digest for the entry: - auto const digest = - ArtifactDigest::CreateFromFile(task.cas.GetHashFunction(), path); + auto const digest = ArtifactDigestFactory::HashFileAs( + task.cas.GetHashFunction(), path); if (not digest) { task.Log(LogLevel::Error, "Failed to calculate digest for {}", diff --git a/src/buildtool/storage/local_cas.tpp b/src/buildtool/storage/local_cas.tpp index e2a77e87..d43bd18b 100644 --- a/src/buildtool/storage/local_cas.tpp +++ b/src/buildtool/storage/local_cas.tpp @@ -19,6 +19,7 @@ #include // std::move #include "fmt/core.h" +#include "src/buildtool/common/artifact_digest_factory.hpp" #include "src/buildtool/common/bazel_types.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/storage/local_cas.hpp" @@ -359,7 +360,7 @@ auto LocalCAS::Splice(ArtifactDigest const& digest, // calculation is done instead. auto const& file_path = large_object.GetPath(); auto spliced_digest = - ArtifactDigest::CreateFromFile(hash_function_, file_path); + ArtifactDigestFactory::HashFileAs(hash_function_, file_path); if (not spliced_digest) { return unexpected{LargeObjectError{LargeObjectErrorCode::Internal, "could not calculate digest"}}; -- cgit v1.2.3