diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-10-31 17:07:14 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-11-14 13:35:01 +0100 |
commit | bc84005095bab7c62faf0ddf08763bd96892e478 (patch) | |
tree | 181b5c868fc475534706bb1c83f8746c10836072 /src/other_tools/root_maps/content_git_map.cpp | |
parent | e4aee9470da57a47d029f15ffa6795fba0398d60 (diff) | |
download | justbuild-bc84005095bab7c62faf0ddf08763bd96892e478.tar.gz |
just-mr: Add 'mirrors' field to archive-like repositories
Also extends 'distdir' repositories logic accordingly.
Diffstat (limited to 'src/other_tools/root_maps/content_git_map.cpp')
-rw-r--r-- | src/other_tools/root_maps/content_git_map.cpp | 69 |
1 files changed, 41 insertions, 28 deletions
diff --git a/src/other_tools/root_maps/content_git_map.cpp b/src/other_tools/root_maps/content_git_map.cpp index bc9f55a2..a39b6cde 100644 --- a/src/other_tools/root_maps/content_git_map.cpp +++ b/src/other_tools/root_maps/content_git_map.cpp @@ -501,6 +501,7 @@ auto CreateContentGitMap( archive_tree_id_file, content = key.archive.content, fetch_url = key.archive.fetch_url, + mirrors = key.archive.mirrors, sha256 = key.archive.sha256, sha512 = key.archive.sha512, pragma_special = key.pragma_special, @@ -707,16 +708,27 @@ auto CreateContentGitMap( /*fatal=*/true); return; } - // now do the actual fetch + // now do the actual fetch; first, try the + // main fetch URL auto data = NetworkFetch(fetch_url, ca_info); - if (data == std::nullopt) { - (*logger)(fmt::format( - "Failed to fetch a file " - "with id {} from {}", - content, - fetch_url), - /*fatal=*/true); + if (not data) { + // try the mirrors, in order, if given + for (auto const& mirror : mirrors) { + data = + NetworkFetch(mirror, ca_info); + if (data) { + break; + } + } + } + if (not data) { + (*logger)( + fmt::format("Failed to fetch a " + "file with content {} " + "from provided remotes", + content), + /*fatal=*/true); return; } // check content wrt checksums @@ -800,8 +812,8 @@ auto CreateContentGitMap( key.archive.content), /*fatal=*/false); } - // if not fetching absent, request the resolved subdir tree - // directly + // if not fetching absent, request the resolved subdir + // tree directly else { if (auto tree_id = serve_api->RetrieveTreeFromArchive( key.archive.content, @@ -837,8 +849,8 @@ auto CreateContentGitMap( } } // revert to network fetch and import_to_git - // before any network fetching, check that mandatory fields are - // provided + // before any network fetching, check that mandatory fields + // are provided if (key.archive.fetch_url.empty()) { (*logger)("Failed to provide archive fetch url!", /*fatal=*/true); @@ -847,11 +859,11 @@ auto CreateContentGitMap( // now do the actual fetch auto data = NetworkFetch(key.archive.fetch_url, ca_info); if (data == std::nullopt) { - (*logger)( - fmt::format("Failed to fetch a file with id {} from {}", - key.archive.content, - key.archive.fetch_url), - /*fatal=*/true); + (*logger)(fmt::format("Failed to fetch a file with id " + "{} from {}", + key.archive.content, + key.archive.fetch_url), + /*fatal=*/true); return; } // check content wrt checksums @@ -885,11 +897,11 @@ auto CreateContentGitMap( auto path = StorageUtils::AddToCAS(*data); // check one last time if content is in CAS now if (not path) { - (*logger)( - fmt::format("Failed to fetch a file with id {} from {}", - key.archive.content, - key.archive.fetch_url), - /*fatal=*/true); + (*logger)(fmt::format("Failed to fetch a file with id " + "{} from {}", + key.archive.content, + key.archive.fetch_url), + /*fatal=*/true); return; } JustMRProgress::Instance().TaskTracker().Stop( @@ -910,7 +922,8 @@ auto CreateContentGitMap( // done return; } - // if not marked absent, do regular fetch to CAS and import_to_git + // if not marked absent, do regular fetch to CAS and + // import_to_git content_cas_map->ConsumeAfterKeysReady( ts, {key.archive}, @@ -948,11 +961,11 @@ auto CreateContentGitMap( }, [logger, content = key.archive.content](auto const& msg, bool fatal) { - (*logger)( - fmt::format("While ensuring content {} is in CAS:\n{}", - content, - msg), - fatal); + (*logger)(fmt::format("While ensuring content {} is in " + "CAS:\n{}", + content, + msg), + fatal); }); } }; |