commit: 9115e1f6ba35cdcd85f2292dc293f0696caa8f12 Author: Michał Górny <mgorny <AT> gentoo <DOT> org> AuthorDate: Fri Oct 18 07:23:02 2019 +0000 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> CommitDate: Sun Oct 20 09:25:10 2019 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=9115e1f6
fetch: Use distfile fetching method to get layout.conf Rewrite the layout.conf getter to reuse the standard fetch() method rather than using urlopen(). While at it, fix negative cache elision to apply to memory cache as well (and not get written to disk if next mirror was fine). Most importantly, this ensures that we respect FETCHCOMMAND while fetching layout.conf, and so layout.conf is fetched the same way normal distfiles are. With some uncommon configurations, the previous disjoint logic might have resulted in one of the fetches failing while the other succeeded. This also adds some nice verbosity. If mirror connection takes a while, the user sees that rather than having Portage wait silently. Bug: https://bugs.gentoo.org/697566 Reviewed-by: Zac Medico <zmedico <AT> gentoo.org> Signed-off-by: Michał Górny <mgorny <AT> gentoo.org> lib/portage/package/ebuild/fetch.py | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/portage/package/ebuild/fetch.py b/lib/portage/package/ebuild/fetch.py index 05de12740..cedf12b19 100644 --- a/lib/portage/package/ebuild/fetch.py +++ b/lib/portage/package/ebuild/fetch.py @@ -382,7 +382,7 @@ class MirrorLayoutConfig(object): return ret -def get_mirror_url(mirror_url, filename, cache_path=None): +def get_mirror_url(mirror_url, filename, mysettings, cache_path=None): """ Get correct fetch URL for a given file, accounting for mirror layout configuration. @@ -408,23 +408,22 @@ def get_mirror_url(mirror_url, filename, cache_path=None): if ts >= time.time() - 86400: mirror_conf.deserialize(data) else: + tmpfile = '.layout.conf.%s' % urlparse(mirror_url).hostname try: - f = urlopen(mirror_url + '/distfiles/layout.conf') - try: - data = io.StringIO(f.read().decode('utf8')) - finally: - f.close() - - mirror_conf.read_from_file(data) + if fetch({tmpfile: (mirror_url + '/distfiles/layout.conf',)}, + mysettings, force=1, try_mirrors=0): + tmpfile = os.path.join(mysettings['DISTDIR'], tmpfile) + mirror_conf.read_from_file(tmpfile) + else: + raise IOError() except (ConfigParserError, IOError, UnicodeDecodeError): - # Do not cache negative results. - cache_path = None - - cache[mirror_url] = (time.time(), mirror_conf.serialize()) - if cache_path is not None: - f = atomic_ofstream(cache_path, 'w') - json.dump(cache, f) - f.close() + pass + else: + cache[mirror_url] = (time.time(), mirror_conf.serialize()) + if cache_path is not None: + f = atomic_ofstream(cache_path, 'w') + json.dump(cache, f) + f.close() return (mirror_url + "/distfiles/" + mirror_conf.get_best_supported_layout().get_path(filename)) @@ -656,7 +655,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, mirror_cache = None for l in locations: filedict[myfile].append(functools.partial( - get_mirror_url, l, myfile, mirror_cache)) + get_mirror_url, l, myfile, mysettings, mirror_cache)) if myuri is None: continue if myuri[:9]=="mirror://":
