diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2025-02-28 16:41:21 +0100 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2025-03-24 09:29:58 +0100 |
commit | 4fbbb6977d73af9958e38bb07e096dee773c9e61 (patch) | |
tree | 56bcdf6e7c37f0e19bbc484b495926796b5b7cb8 /src/buildtool/common/artifact_blob.hpp | |
parent | f192705cb4834252507d228e7d6e0a38095976e3 (diff) | |
download | justbuild-4fbbb6977d73af9958e38bb07e096dee773c9e61.tar.gz |
ArtifactBlob: Support construction from temporary files
Diffstat (limited to 'src/buildtool/common/artifact_blob.hpp')
-rw-r--r-- | src/buildtool/common/artifact_blob.hpp | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/buildtool/common/artifact_blob.hpp b/src/buildtool/common/artifact_blob.hpp index 092dd2b1..1e54f71b 100644 --- a/src/buildtool/common/artifact_blob.hpp +++ b/src/buildtool/common/artifact_blob.hpp @@ -28,6 +28,7 @@ #include "src/buildtool/file_system/object_type.hpp" #include "src/utils/cpp/expected.hpp" #include "src/utils/cpp/incremental_reader.hpp" +#include "src/utils/cpp/tmp_dir.hpp" class ArtifactBlob final { public: @@ -54,6 +55,33 @@ class ArtifactBlob final { std::filesystem::path file) noexcept -> expected<ArtifactBlob, std::string>; + /// \brief Create ArtifactBlob based on the existing temporary file. The + /// content is hashed based on the given hash function and ObjectType. + /// \param hash_function HashFunction that must be used for hashing. + /// \param type Type of the content. + /// \param file Temporary file to be used as the source of + /// content. + /// \return Valid ArtifactBlob on success or an error message on failure. + [[nodiscard]] static auto FromTempFile(HashFunction hash_function, + ObjectType type, + TmpFile::Ptr file) noexcept + -> expected<ArtifactBlob, std::string>; + + /// \brief Create ArtifactBlob and write the given content to the temporary + /// space. The content is hashed based on the given hash function and + /// ObjectType. + /// \param hash_function HashFunction that must be used for hashing. + /// \param type Type of the content. + /// \param temp_space Temporary space where a new temporary file may + /// be created. + /// \param content Content to be stored in the temporary file. + /// \return Valid ArtifactBlob on success or an error message on failure. + [[nodiscard]] static auto FromTempFile(HashFunction hash_type, + ObjectType type, + TmpDir::Ptr const& temp_space, + std::string const& content) noexcept + -> expected<ArtifactBlob, std::string>; + [[nodiscard]] auto operator==(ArtifactBlob const& other) const noexcept -> bool { return digest_ == other.digest_ and @@ -96,7 +124,8 @@ class ArtifactBlob final { private: using InMemory = std::shared_ptr<std::string const>; using InFile = std::filesystem::path; - using ContentSource = std::variant<InMemory, InFile>; + using InTempFile = TmpFile::Ptr; + using ContentSource = std::variant<InMemory, InFile, InTempFile>; ArtifactDigest digest_; ContentSource content_; |