diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2024-03-06 18:37:11 +0100 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2024-03-08 14:18:43 +0100 |
commit | ef952e26a565db3465b3f5674f496cd1e5e2ae0e (patch) | |
tree | 9f9d612f8462b606b2c2d8ef430c70b429dda733 /src/other_tools/utils | |
parent | be96de5702039e034b51e1e2434a6838d6760e1b (diff) | |
download | justbuild-ef952e26a565db3465b3f5674f496cd1e5e2ae0e.tar.gz |
just-mr: Fix "preferred hostnames"
... instead of replacing the host name of each mirror, it
should only reorder the list of given mirrors.
Diffstat (limited to 'src/other_tools/utils')
-rw-r--r-- | src/other_tools/utils/content.hpp | 82 |
1 files changed, 18 insertions, 64 deletions
diff --git a/src/other_tools/utils/content.hpp b/src/other_tools/utils/content.hpp index 5f593225..b1308a97 100644 --- a/src/other_tools/utils/content.hpp +++ b/src/other_tools/utils/content.hpp @@ -53,79 +53,33 @@ -> std::variant<std::string, std::string> { // keep all remotes tried, to report in case fetch fails std::string remotes_buffer{}; - // first, try the local mirrors std::optional<std::string> data{std::nullopt}; + + // try repo url + auto all_mirrors = std::vector<std::string>({fetch_url}); + // try repo mirrors afterwards + all_mirrors.insert(all_mirrors.end(), mirrors.begin(), mirrors.end()); + + if (auto preferred_hostnames = + MirrorsUtils::GetPreferredHostnames(additional_mirrors); + not preferred_hostnames.empty()) { + all_mirrors = + MirrorsUtils::SortByHostname(all_mirrors, preferred_hostnames); + } + + // always try local mirrors first auto local_mirrors = MirrorsUtils::GetLocalMirrors(additional_mirrors, fetch_url); - for (auto const& mirror : local_mirrors) { + all_mirrors.insert( + all_mirrors.begin(), local_mirrors.begin(), local_mirrors.end()); + + for (auto const& mirror : all_mirrors) { if (data = NetworkFetch(mirror, ca_info); data) { break; } // add local mirror to buffer remotes_buffer.append(fmt::format("\n> {}", mirror)); } - if (not data) { - // get preferred hostnames list - auto preferred_hostnames = - MirrorsUtils::GetPreferredHostnames(additional_mirrors); - // try the main fetch URL, but with each of the preferred hostnames - for (auto const& hostname : preferred_hostnames) { - if (auto preferred_url = - CurlURLHandle::ReplaceHostname(fetch_url, hostname)) { - if (data = NetworkFetch(*preferred_url, ca_info); data) { - break; - } - // add preferred URL to buffer - remotes_buffer.append(fmt::format("\n> {}", *preferred_url)); - } - else { - // report failed hostname - remotes_buffer.append( - fmt::format("\n> {} (failed hostname replace: {})", - fetch_url, - hostname)); - } - } - if (not data) { - // now try the main fetch URL - if (data = NetworkFetch(fetch_url, ca_info); not data) { - // add main fetch URL to buffer - remotes_buffer.append(fmt::format("\n> {}", fetch_url)); - // try the mirrors, in order, if given - for (auto const& mirror : mirrors) { - // first use with preferred hostnames... - for (auto const& hostname : preferred_hostnames) { - if (auto preferred_mirror = - CurlURLHandle::ReplaceHostname(mirror, - hostname)) { - if (data = NetworkFetch(*preferred_mirror, ca_info); - data) { - break; - } - // add preferred mirror to buffer - remotes_buffer.append( - fmt::format("\n> {}", *preferred_mirror)); - } - else { - // report failed hostname - remotes_buffer.append(fmt::format( - "\n> {} (failed hostname replace: {})", - mirror, - hostname)); - } - } - // ...then the original mirror - if (not data) { - if (data = NetworkFetch(mirror, ca_info); data) { - break; - } - // add mirror to buffer - remotes_buffer.append(fmt::format("\n> {}", mirror)); - } - } - } - } - } return data ? std::variant<std::string, std::string>(std::in_place_index<1>, *data) : std::variant<std::string, std::string>(std::in_place_index<0>, |