diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-01-03 12:23:38 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-01-08 15:36:34 +0100 |
commit | 90b14e410105258bdc052c5677b95ae48915b45e (patch) | |
tree | 73857b33e2c5f0501ae76d7253f9478803a00d57 /src | |
parent | 3373d0f555f6325e1242acb7ce126778bc421d17 (diff) | |
download | justbuild-90b14e410105258bdc052c5677b95ae48915b45e.tar.gz |
serve archive tree: Add missing check for content in local CAS
When serving the tree of an archive, we should check also in the
local CAS for the content blob.
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/serve_api/serve_service/source_tree.cpp | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/buildtool/serve_api/serve_service/source_tree.cpp b/src/buildtool/serve_api/serve_service/source_tree.cpp index 739abc36..51c9da55 100644 --- a/src/buildtool/serve_api/serve_service/source_tree.cpp +++ b/src/buildtool/serve_api/serve_service/source_tree.cpp @@ -648,12 +648,18 @@ auto SourceTreeService::ServeArchiveTree( response->set_status(ServeArchiveTreeResponse::INTERNAL_ERROR); return ::grpc::Status::OK; } + // check if content is in local CAS already + auto digest = ArtifactDigest(content, 0, false); + auto const& cas = Storage::Instance().CAS(); std::optional<std::filesystem::path> content_cas_path{std::nullopt}; - // check if content blob is in Git cache - if (auto data = - GetBlobFromRepo(StorageConfig::GitRoot(), content, logger_)) { - // add to CAS - content_cas_path = StorageUtils::AddToCAS(*data); + if (content_cas_path = cas.BlobPath(digest, /*is_executable=*/false); + not content_cas_path) { + // check if content blob is in Git cache + if (auto data = + GetBlobFromRepo(StorageConfig::GitRoot(), content, logger_)) { + // add to CAS + content_cas_path = StorageUtils::AddToCAS(*data); + } } if (not content_cas_path) { // check if content blob is in a known repository @@ -669,7 +675,6 @@ auto SourceTreeService::ServeArchiveTree( } if (not content_cas_path) { // try to retrieve it from remote CAS - auto digest = ArtifactDigest(content, 0, false); if (not(remote_api_->IsAvailable(digest) and remote_api_->RetrieveToCas( {Artifact::ObjectInfo{.digest = digest, @@ -680,9 +685,14 @@ auto SourceTreeService::ServeArchiveTree( return ::grpc::Status::OK; } // content should now be in CAS - auto const& cas = Storage::Instance().CAS(); - content_cas_path = - cas.BlobPath(digest, /*is_executable=*/false).value(); + content_cas_path = cas.BlobPath(digest, /*is_executable=*/false); + if (not content_cas_path) { + auto str = fmt::format( + "Retrieving content {} from CAS failed unexpectedly", content); + logger_->Emit(LogLevel::Error, str); + response->set_status(ServeArchiveTreeResponse::INTERNAL_ERROR); + return ::grpc::Status::OK; + } } // extract archive auto tmp_dir = StorageUtils::CreateTypedTmpDir(archive_type); |