diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2025-02-25 15:18:44 +0100 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2025-02-27 09:03:30 +0100 |
commit | 0f87d4fb45d27e3f169de99bd4196ebc6eca5e33 (patch) | |
tree | 89e3882ca365cabef7557381ee99925441ae0454 /src/buildtool/common/artifact_blob.hpp | |
parent | 9ef9974db0941587453891e3250ffed8de7e10f1 (diff) | |
download | justbuild-0f87d4fb45d27e3f169de99bd4196ebc6eca5e33.tar.gz |
ArtifactBlob: Support construction from an existing file
Diffstat (limited to 'src/buildtool/common/artifact_blob.hpp')
-rw-r--r-- | src/buildtool/common/artifact_blob.hpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/buildtool/common/artifact_blob.hpp b/src/buildtool/common/artifact_blob.hpp index c5a03cf9..092dd2b1 100644 --- a/src/buildtool/common/artifact_blob.hpp +++ b/src/buildtool/common/artifact_blob.hpp @@ -16,6 +16,7 @@ #define INCLUDED_SRC_BUILDTOOL_COMMON_ARTIFACT_BLOB_HPP #include <cstddef> +#include <filesystem> #include <functional> #include <memory> #include <string> @@ -41,6 +42,18 @@ class ArtifactBlob final { std::string content) noexcept -> expected<ArtifactBlob, std::string>; + /// \brief Create ArtifactBlob based on the existing file. The content is + /// hashed based on the given hash function and ObjectType. + /// \param hash_function Hash function that must be used for hashing. + /// \param type Type of the content. + /// \param file Existing file to be used as the source of + /// content. + /// \return Valid ArtifactBlob on success or an error message on failure. + [[nodiscard]] static auto FromFile(HashFunction hash_function, + ObjectType type, + std::filesystem::path file) noexcept + -> expected<ArtifactBlob, std::string>; + [[nodiscard]] auto operator==(ArtifactBlob const& other) const noexcept -> bool { return digest_ == other.digest_ and @@ -57,7 +70,8 @@ class ArtifactBlob final { return digest_.size(); } - /// \brief Read the content from source. + /// \brief Read the content from source. This operation may result in the + /// entire file being read into memory. [[nodiscard]] auto ReadContent() const noexcept -> std::shared_ptr<std::string const>; @@ -81,7 +95,8 @@ class ArtifactBlob final { private: using InMemory = std::shared_ptr<std::string const>; - using ContentSource = std::variant<InMemory>; + using InFile = std::filesystem::path; + using ContentSource = std::variant<InMemory, InFile>; ArtifactDigest digest_; ContentSource content_; |