summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-03-12 10:16:52 +0100
committerMaksim Denisov <denisov.maksim@huawei.com>2024-04-02 15:30:03 +0200
commit3972baff6099e33edfcbee733bd8784ec5972b8f (patch)
tree9ca3c5c2f1fa55ee9cf383bd34a20a744027fcbe
parentd5365822cd7d574bc1bf87e1e1f876d88d88f3e0 (diff)
downloadjustbuild-3972baff6099e33edfcbee733bd8784ec5972b8f.tar.gz
ObjectCAS: Move the method for calculating file digests to the public space.
This is needed for LocalCAS's splice routines.
-rw-r--r--src/buildtool/file_system/object_cas.hpp27
1 files changed, 15 insertions, 12 deletions
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<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 =
@@ -113,18 +128,6 @@ class ObjectCAS {
return ArtifactDigest::Create<kType>(bytes);
}
- [[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;
- }
-
[[nodiscard]] auto IsAvailable(
bazel_re::Digest const& digest,
std::filesystem::path const& path) const noexcept -> bool {