diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2025-02-28 16:59:32 +0100 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2025-03-24 09:33:46 +0100 |
commit | 538c7f3e180a5f121c6819ad5d9b14f843512f60 (patch) | |
tree | eb496a15d8c9f29e443ab107d35ff0a9990ba4e0 /src | |
parent | 4fbbb6977d73af9958e38bb07e096dee773c9e61 (diff) | |
download | justbuild-538c7f3e180a5f121c6819ad5d9b14f843512f60.tar.gz |
ArtifactBlob: Return file path
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/common/artifact_blob.cpp | 16 | ||||
-rw-r--r-- | src/buildtool/common/artifact_blob.hpp | 7 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/buildtool/common/artifact_blob.cpp b/src/buildtool/common/artifact_blob.cpp index 8c48d34e..c46e54c6 100644 --- a/src/buildtool/common/artifact_blob.cpp +++ b/src/buildtool/common/artifact_blob.cpp @@ -15,7 +15,6 @@ #include "src/buildtool/common/artifact_blob.hpp" #include <exception> -#include <optional> #include "fmt/core.h" #include "src/buildtool/common/artifact_digest_factory.hpp" @@ -202,6 +201,21 @@ auto ArtifactBlob::ReadIncrementally(std::size_t chunk_size) const& noexcept } } +auto ArtifactBlob::GetFilePath() const& noexcept + -> std::optional<std::filesystem::path> { + using Result = std::optional<std::filesystem::path>; + static constexpr InPlaceVisitor kVisitor{ + [](InMemory const&) -> Result { return std::nullopt; }, + [](InFile const& value) -> Result { return value; }, + [](InTempFile const& value) -> Result { return value->GetPath(); }, + }; + try { + return std::visit(kVisitor, content_); + } catch (...) { + return std::nullopt; + } +} + namespace std { auto hash<ArtifactBlob>::operator()(ArtifactBlob const& blob) const noexcept -> std::size_t { diff --git a/src/buildtool/common/artifact_blob.hpp b/src/buildtool/common/artifact_blob.hpp index 1e54f71b..1847e536 100644 --- a/src/buildtool/common/artifact_blob.hpp +++ b/src/buildtool/common/artifact_blob.hpp @@ -19,6 +19,7 @@ #include <filesystem> #include <functional> #include <memory> +#include <optional> #include <string> #include <utility> #include <variant> @@ -111,6 +112,12 @@ class ArtifactBlob final { [[nodiscard]] auto ReadIncrementally(std::size_t chunk_size) const& noexcept -> expected<IncrementalReader, std::string>; + /// \brief Obtain the path to the file that is used as the content source. + /// If ArtifactBlob doesn't use a filesystem source or an internal error + /// occurs, std::nullopt is returned. + [[nodiscard]] auto GetFilePath() const& noexcept + -> std::optional<std::filesystem::path>; + /// \brief Set executable permission. void SetExecutable(bool is_executable) noexcept { is_executable_ = is_executable; |