summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/common/artifact.hpp29
-rw-r--r--src/buildtool/storage/target_cache.tpp6
2 files changed, 25 insertions, 10 deletions
diff --git a/src/buildtool/common/artifact.hpp b/src/buildtool/common/artifact.hpp
index ec36964e..a788075a 100644
--- a/src/buildtool/common/artifact.hpp
+++ b/src/buildtool/common/artifact.hpp
@@ -25,6 +25,8 @@
#include "nlohmann/json.hpp"
#include "src/buildtool/common/artifact_digest.hpp"
#include "src/buildtool/common/identifier.hpp"
+#include "src/buildtool/crypto/hash_function.hpp"
+#include "src/buildtool/crypto/hash_info.hpp"
#include "src/buildtool/file_system/object_type.hpp"
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
@@ -68,7 +70,8 @@ class Artifact {
{"file_type", std::string{ToChar(type)}}};
}
- [[nodiscard]] static auto FromString(std::string const& s) noexcept
+ [[nodiscard]] static auto FromString(HashFunction::Type hash_type,
+ std::string const& s) noexcept
-> std::optional<ObjectInfo> {
std::istringstream iss(s);
std::string id{};
@@ -81,21 +84,31 @@ class Artifact {
"failed parsing object info from string.");
return std::nullopt;
}
+
+ std::size_t size = 0;
try {
- std::size_t size = std::stoul(size_str);
- auto const& object_type = FromChar(*type.c_str());
- return ObjectInfo{
- .digest =
- ArtifactDigest{id, size, IsTreeObject(object_type)},
- .type = object_type};
+ size = std::stoul(size_str);
} catch (std::out_of_range const& e) {
Logger::Log(LogLevel::Debug,
"size raised out_of_range exception.");
+ return std::nullopt;
} catch (std::invalid_argument const& e) {
Logger::Log(LogLevel::Debug,
"size raised invalid_argument exception.");
+ return std::nullopt;
+ }
+
+ auto const object_type = FromChar(*type.c_str());
+ auto hash_info =
+ HashInfo::Create(hash_type, id, IsTreeObject(object_type));
+ if (not hash_info) {
+ Logger::Log(
+ LogLevel::Debug, "{}", std::move(hash_info).error());
+ return std::nullopt;
}
- return std::nullopt;
+ return ObjectInfo{
+ .digest = ArtifactDigest{*std::move(hash_info), size},
+ .type = object_type};
}
};
diff --git a/src/buildtool/storage/target_cache.tpp b/src/buildtool/storage/target_cache.tpp
index be1b9560..f19a37d5 100644
--- a/src/buildtool/storage/target_cache.tpp
+++ b/src/buildtool/storage/target_cache.tpp
@@ -86,7 +86,8 @@ auto TargetCache<kDoGlobalUplink>::Read(
entry_path.string());
return std::nullopt;
}
- if (auto info = Artifact::ObjectInfo::FromString(*entry)) {
+ auto const hash_type = cas_.GetHashFunction().GetType();
+ if (auto info = Artifact::ObjectInfo::FromString(hash_type, *entry)) {
if (auto path = cas_.BlobPath(info->digest, /*is_executable=*/false)) {
if (auto value = FileSystemManager::ReadFile(*path)) {
try {
@@ -136,7 +137,8 @@ auto TargetCache<kDoGlobalUplink>::LocalUplinkEntry(
}
// Determine target cache entry location.
- auto entry_info = Artifact::ObjectInfo::FromString(*raw_key);
+ auto entry_info = Artifact::ObjectInfo::FromString(
+ cas_.GetHashFunction().GetType(), *raw_key);
if (not entry_info) {
return false;
}