summaryrefslogtreecommitdiff
path: root/src/buildtool/serve_api/serve_service/source_tree.cpp
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-09-12 10:13:19 +0200
committerMaksim Denisov <denisov.maksim@huawei.com>2024-09-13 14:41:00 +0200
commit0e472f5cfbcfde7edb968ae39daa935dee9bb27b (patch)
treedc301df0c02c1af9f0239e1228b82363e61982b0 /src/buildtool/serve_api/serve_service/source_tree.cpp
parent53893aa9c7109ab157afecc4f073a27b32d372b4 (diff)
downloadjustbuild-0e472f5cfbcfde7edb968ae39daa935dee9bb27b.tar.gz
Check compatibility in serve services based on the hash type
Diffstat (limited to 'src/buildtool/serve_api/serve_service/source_tree.cpp')
-rw-r--r--src/buildtool/serve_api/serve_service/source_tree.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/buildtool/serve_api/serve_service/source_tree.cpp b/src/buildtool/serve_api/serve_service/source_tree.cpp
index ed6fcae0..567d61bb 100644
--- a/src/buildtool/serve_api/serve_service/source_tree.cpp
+++ b/src/buildtool/serve_api/serve_service/source_tree.cpp
@@ -287,7 +287,8 @@ auto SourceTreeService::SyncGitEntryToCas(
std::string const& object_hash,
std::filesystem::path const& repo_path) const noexcept
-> std::remove_cvref_t<decltype(TResponse::OK)> {
- if (IsTreeObject(kType) and ProtocolTraits::Instance().IsCompatible()) {
+ auto const hash_type = storage_config_.hash_function.GetType();
+ if (IsTreeObject(kType) and not ProtocolTraits::IsTreeAllowed(hash_type)) {
logger_->Emit(LogLevel::Error,
"Cannot sync tree {} from repository {} with "
"the remote in compatible mode",
@@ -302,11 +303,8 @@ auto SourceTreeService::SyncGitEntryToCas(
LogLevel::Error, "Failed to SetGitCAS at {}", repo_path.string());
return TResponse::INTERNAL_ERROR;
}
- auto const digest =
- ArtifactDigestFactory::Create(storage_config_.hash_function.GetType(),
- object_hash,
- 0,
- IsTreeObject(kType));
+ auto const digest = ArtifactDigestFactory::Create(
+ hash_type, object_hash, 0, IsTreeObject(kType));
if (not digest) {
logger_->Emit(LogLevel::Error, "{}", digest.error());
return TResponse::INTERNAL_ERROR;
@@ -967,6 +965,8 @@ auto SourceTreeService::ServeDistdirTree(
content_list{};
content_list.reserve(request->distfiles().size());
+ bool const is_native =
+ ProtocolTraits::IsNative(storage_config_.hash_function.GetType());
for (auto const& kv : request->distfiles()) {
bool blob_found{};
std::string blob_digest; // The digest of the requested distfile, taken
@@ -984,7 +984,7 @@ auto SourceTreeService::ServeDistdirTree(
0,
/*is_tree=*/false);
- if (not ProtocolTraits::Instance().IsCompatible()) {
+ if (is_native) {
blob_found = digest and cas.BlobPath(*digest, kv.executable());
}
if (blob_found) {
@@ -1054,8 +1054,8 @@ auto SourceTreeService::ServeDistdirTree(
}
if (not blob_found) {
// check remote CAS
- if (not ProtocolTraits::Instance().IsCompatible() and
- digest and apis_.remote->IsAvailable(*digest)) {
+ if (is_native and digest and
+ apis_.remote->IsAvailable(*digest)) {
// retrieve content to local CAS
if (not apis_.remote->RetrieveToCas(
{Artifact::ObjectInfo{
@@ -1316,11 +1316,12 @@ auto SourceTreeService::ServeTree(
}
}
// check also in the local CAS
- auto const digest = ArtifactDigestFactory::Create(
- storage_config_.hash_function.GetType(), tree_id, 0, /*is_tree=*/true);
+ auto const hash_type = storage_config_.hash_function.GetType();
+ auto const digest =
+ ArtifactDigestFactory::Create(hash_type, tree_id, 0, /*is_tree=*/true);
if (digest and apis_.local->IsAvailable(*digest)) {
// upload tree to remote CAS; only possible in native mode
- if (ProtocolTraits::Instance().IsCompatible()) {
+ if (not ProtocolTraits::IsNative(hash_type)) {
logger_->Emit(LogLevel::Error,
"Cannot sync tree {} from local CAS with the remote "
"in compatible mode",