diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-02-23 16:35:34 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-02-27 14:35:44 +0100 |
commit | 0e913dd3eee248bccf2b26161ca0a715d039e716 (patch) | |
tree | 3bfac4df42c9759dfe60cb7621ad782d422b7674 /src/other_tools/ops_maps/archive_fetch_map.cpp | |
parent | 842145ff59594be8624390e22d815c71bc5c85d6 (diff) | |
download | justbuild-0e913dd3eee248bccf2b26161ca0a715d039e716.tar.gz |
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.
Diffstat (limited to 'src/other_tools/ops_maps/archive_fetch_map.cpp')
-rw-r--r-- | src/other_tools/ops_maps/archive_fetch_map.cpp | 87 |
1 files changed, 35 insertions, 52 deletions
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<IExecutionApi*> const& local_api, std::optional<gsl::not_null<IExecutionApi*>> 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<ArchiveRepoInfo, bool>(fetch_archive, jobs); } |