From 3972baff6099e33edfcbee733bd8784ec5972b8f Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Tue, 12 Mar 2024 10:16:52 +0100 Subject: ObjectCAS: Move the method for calculating file digests to the public space. This is needed for LocalCAS's splice routines. --- src/buildtool/file_system/object_cas.hpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/buildtool/file_system/object_cas.hpp b/src/buildtool/file_system/object_cas.hpp index 93b2055b..6dd1ae9f 100644 --- a/src/buildtool/file_system/object_cas.hpp +++ b/src/buildtool/file_system/object_cas.hpp @@ -97,6 +97,21 @@ 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 { + 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 = @@ -113,18 +128,6 @@ class ObjectCAS { return ArtifactDigest::Create(bytes); } - [[nodiscard]] static auto CreateDigest( - std::filesystem::path const& file_path) noexcept - -> std::optional { - 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; - } - [[nodiscard]] auto IsAvailable( bazel_re::Digest const& digest, std::filesystem::path const& path) const noexcept -> bool { -- cgit v1.2.3