diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/common/artifact_digest.hpp | 13 | ||||
-rw-r--r-- | src/buildtool/file_system/object_cas.hpp | 23 | ||||
-rw-r--r-- | src/buildtool/storage/compactifier.cpp | 4 | ||||
-rw-r--r-- | src/buildtool/storage/local_cas.hpp | 1 | ||||
-rw-r--r-- | src/buildtool/storage/local_cas.tpp | 2 |
5 files changed, 24 insertions, 19 deletions
diff --git a/src/buildtool/common/artifact_digest.hpp b/src/buildtool/common/artifact_digest.hpp index 2ad94c27..8cbf6ccc 100644 --- a/src/buildtool/common/artifact_digest.hpp +++ b/src/buildtool/common/artifact_digest.hpp @@ -90,6 +90,19 @@ class ArtifactDigest { } } + template <ObjectType kType> + [[nodiscard]] static auto CreateFromFile( + std::filesystem::path const& path) noexcept + -> std::optional<ArtifactDigest> { + static constexpr bool kIsTree = IsTreeObject(kType); + auto hash = HashFunction::ComputeHashFile(path, kIsTree); + if (hash) { + return ArtifactDigest{ + hash->first.HexString(), hash->second, kIsTree}; + } + return std::nullopt; + } + [[nodiscard]] auto operator<(ArtifactDigest const& other) const -> bool { return (hash_ < other.hash_) or ((hash_ == other.hash_) and (static_cast<int>(is_tree_) < diff --git a/src/buildtool/file_system/object_cas.hpp b/src/buildtool/file_system/object_cas.hpp index 185dc26a..aa521e07 100644 --- a/src/buildtool/file_system/object_cas.hpp +++ b/src/buildtool/file_system/object_cas.hpp @@ -20,7 +20,7 @@ #include <thread> #include <utility> // std::move -#include "src/buildtool/common/artifact.hpp" +#include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/common/bazel_types.hpp" #include "src/buildtool/file_system/file_storage.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" @@ -103,21 +103,6 @@ class ObjectCAS { return blob_path; } - /// \brief Calculate the digest for a file. - /// \param file_path File for which the digest needs to be calculated. - /// \return File digest. - [[nodiscard]] static auto CreateDigest( - std::filesystem::path const& file_path) noexcept - -> std::optional<bazel_re::Digest> { - bool is_tree = kType == ObjectType::Tree; - auto hash = HashFunction::ComputeHashFile(file_path, is_tree); - if (hash) { - return ArtifactDigest( - hash->first.HexString(), hash->second, is_tree); - } - return std::nullopt; - } - private: // For `Tree` the underlying storage type is non-executable file. static constexpr auto kStorageType = @@ -134,6 +119,12 @@ class ObjectCAS { return ArtifactDigest::Create<kType>(bytes); } + [[nodiscard]] static auto CreateDigest( + std::filesystem::path const& file_path) noexcept + -> std::optional<bazel_re::Digest> { + return ArtifactDigest::CreateFromFile<kType>(file_path); + } + [[nodiscard]] auto IsAvailable( bazel_re::Digest const& digest, std::filesystem::path const& path) const noexcept -> bool { diff --git a/src/buildtool/storage/compactifier.cpp b/src/buildtool/storage/compactifier.cpp index e9997efb..7dac4a06 100644 --- a/src/buildtool/storage/compactifier.cpp +++ b/src/buildtool/storage/compactifier.cpp @@ -21,12 +21,12 @@ #include <optional> #include <vector> +#include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/common/bazel_types.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/crypto/hasher.hpp" #include "src/buildtool/file_system/file_storage.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" -#include "src/buildtool/file_system/object_cas.hpp" #include "src/buildtool/file_system/object_type.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/logger.hpp" @@ -271,7 +271,7 @@ template <ObjectType kType> } // Calculate the digest for the entry: - auto const digest = ObjectCAS<kType>::CreateDigest(path); + auto const digest = ArtifactDigest::CreateFromFile<kType>(path); if (not digest) { task.Log(LogLevel::Error, "Failed to calculate digest for {}", diff --git a/src/buildtool/storage/local_cas.hpp b/src/buildtool/storage/local_cas.hpp index cbaa0439..aedf5838 100644 --- a/src/buildtool/storage/local_cas.hpp +++ b/src/buildtool/storage/local_cas.hpp @@ -21,6 +21,7 @@ #include <vector> #include "gsl/gsl" +#include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/file_system/git_repo.hpp" #include "src/buildtool/file_system/object_cas.hpp" #include "src/buildtool/storage/config.hpp" diff --git a/src/buildtool/storage/local_cas.tpp b/src/buildtool/storage/local_cas.tpp index 97ecf1a3..8bb04049 100644 --- a/src/buildtool/storage/local_cas.tpp +++ b/src/buildtool/storage/local_cas.tpp @@ -374,7 +374,7 @@ auto LocalCAS<kDoGlobalUplink>::Splice( // methods can refer to a file that existed before. The direct hash // calculation is done instead. auto const& file_path = large_object.GetPath(); - auto spliced_digest = ObjectCAS<kType>::CreateDigest(file_path); + auto spliced_digest = ArtifactDigest::CreateFromFile<kType>(file_path); if (not spliced_digest) { return unexpected{LargeObjectError{LargeObjectErrorCode::Internal, "could not calculate digest"}}; |