aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2019-10-18 09:23:02 +0200
committerMichał Górny <mgorny@gentoo.org>2019-10-20 11:25:10 +0200
commit9115e1f6ba35cdcd85f2292dc293f0696caa8f12 (patch)
tree611fbd67c187581e41e5a525ce85a4506aa3da3e
parentfetch: add force parameter (bug 697566) (diff)
downloadportage-9115e1f6ba35cdcd85f2292dc293f0696caa8f12.tar.gz
portage-9115e1f6ba35cdcd85f2292dc293f0696caa8f12.tar.bz2
portage-9115e1f6ba35cdcd85f2292dc293f0696caa8f12.zip
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@gentoo.org> Signed-off-by: Michał Górny <mgorny@gentoo.org>
-rw-r--r--lib/portage/package/ebuild/fetch.py33
1 files 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://":