commit: 8135cbae9af26928950d57a0b5adb50480720a6e Author: Ben Torkington <prmera <AT> gmail <DOT> com> AuthorDate: Wed Mar 4 00:55:07 2026 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Wed Mar 4 03:56:29 2026 +0000 URL: https://gitweb.gentoo.org/proj/mirrorselect.git/commit/?id=8135cbae
add helper method for joining URLs urllib turns out to be bad at this, and breaks URLs with protocols like rsync, so it looks like string concat is the best approach here. Signed-off-by: Ben Torkington <prmera <AT> gmail.com> Part-of: https://codeberg.org/gentoo/mirrorselect/pulls/3 Signed-off-by: Sam James <sam <AT> gentoo.org> mirrorselect/selectors.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/mirrorselect/selectors.py b/mirrorselect/selectors.py index ead8584..b48d9e8 100644 --- a/mirrorselect/selectors.py +++ b/mirrorselect/selectors.py @@ -305,10 +305,7 @@ class Deep: """ self.output.write("\n_deeptime(): maxtime is %s\n" % maxtime, 2) - if url.endswith("/"): # append the path to the testfile to the URL - url = url + "distfiles/" + self.test_file - else: - url = url + "/distfiles/" + self.test_file + dist_url = Deep._urljoin(url, "distfiles") url_parts = url_parse(url) @@ -557,6 +554,23 @@ class Deep: return retval, host_dict + @staticmethod + def _urljoin(url, path): + """Appends a path component to a URL string. + + urllib's urljoin can't be relied on for this. If the given URL + doesn't end with a slash, the last component is *replaced* instead + of concatenated to. + + In addition, urllib.parse requires a workaround for other protocols + such as rsync, otherwise the given path component simply replaces + the URL. + """ + if not url.endswith("/"): + url = url + "/" + + return url + path + class Interactive: """Handles interactive host selection."""
