From 0e913dd3eee248bccf2b26161ca0a715d039e716 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Fri, 23 Feb 2024 16:35:34 +0100 Subject: just-mr setup archive: Local roots require the archive blob to be local too For archive repositories we need to ensure that a non-absent root is backed by an archive content blob in the local CAS, in order to also keep the proper root tree file associations. This change also simplifies the content_cas_map logic by removing the previous separation of implementation logic between fetching and setting up the workspace root. --- src/other_tools/ops_maps/archive_fetch_map.cpp | 87 +++++++++++--------------- 1 file changed, 35 insertions(+), 52 deletions(-) (limited to 'src/other_tools/ops_maps/archive_fetch_map.cpp') diff --git a/src/other_tools/ops_maps/archive_fetch_map.cpp b/src/other_tools/ops_maps/archive_fetch_map.cpp index f2b5842b..ab4ca7e8 100644 --- a/src/other_tools/ops_maps/archive_fetch_map.cpp +++ b/src/other_tools/ops_maps/archive_fetch_map.cpp @@ -32,14 +32,14 @@ void ProcessContent( gsl::not_null const& local_api, std::optional> const& remote_api, std::string const& content, - ArtifactDigest const& digest, ArchiveFetchMap::SetterPtr const& setter, ArchiveFetchMap::LoggerPtr const& logger) { // try to back up to remote CAS if (remote_api) { if (not local_api->RetrieveToCas( - {Artifact::ObjectInfo{.digest = digest, - .type = ObjectType::File}}, + {Artifact::ObjectInfo{ + .digest = ArtifactDigest{content, 0, /*is_tree=*/false}, + .type = ObjectType::File}}, *remote_api)) { // give a warning (*logger)(fmt::format("Failed to back up content {} from local CAS " @@ -87,55 +87,38 @@ auto CreateArchiveFetchMap( .filename() .string()); auto target_name = fetch_dir / distfile; - // check if content not already in CAS - auto digest = ArtifactDigest(key.archive.content, 0, false); - auto const& cas = Storage::Instance().CAS(); - auto content_path = cas.BlobPath(digest, - /*is_executable=*/false); - if (not content_path) { - // make sure content is in CAS - content_cas_map->ConsumeAfterKeysReady( - ts, - {key.archive}, - [target_name, - local_api, - remote_api, - content = key.archive.content, - digest = std::move(digest), - setter, - logger]([[maybe_unused]] auto const& values) { - auto const& cas = Storage::Instance().CAS(); - auto content_path = cas.BlobPath(digest, - /*is_executable=*/false) - .value(); - ProcessContent(content_path, - target_name, - local_api, - remote_api, - content, - digest, - setter, - logger); - }, - [logger, content = key.archive.content](auto const& msg, - bool fatal) { - (*logger)( - fmt::format("While ensuring content {} is in CAS:\n{}", - content, - msg), - fatal); - }); - } - else { - ProcessContent(*content_path, - target_name, - local_api, - remote_api, - key.archive.content, - digest, - setter, - logger); - } + // make sure content is in CAS + content_cas_map->ConsumeAfterKeysReady( + ts, + {key.archive}, + [target_name, + local_api, + remote_api, + content = key.archive.content, + setter, + logger]([[maybe_unused]] auto const& values) { + // content is in local CAS now + auto const& cas = Storage::Instance().CAS(); + auto content_path = + cas.BlobPath(ArtifactDigest{content, 0, /*is_tree=*/false}, + /*is_executable=*/false) + .value(); + ProcessContent(content_path, + target_name, + local_api, + remote_api, + content, + setter, + logger); + }, + [logger, content = key.archive.content](auto const& msg, + bool fatal) { + (*logger)( + fmt::format("While ensuring content {} is in CAS:\n{}", + content, + msg), + fatal); + }); }; return AsyncMapConsumer(fetch_archive, jobs); } -- cgit v1.2.3