1 |
Rewrite the layout.conf getter to reuse the standard fetch() method |
2 |
rather than using urlopen(). While at it, fix negative cache elision |
3 |
to apply to memory cache as well (and not get written to disk if next |
4 |
mirror was fine). |
5 |
|
6 |
Most importantly, this ensures that we respect FETCHCOMMAND while |
7 |
fetching layout.conf, and so layout.conf is fetched the same way normal |
8 |
distfiles are. With some uncommon configurations, the previous disjoint |
9 |
logic might have resulted in one of the fetches failing while the other |
10 |
succeeded. |
11 |
|
12 |
This also adds some nice verbosity. If mirror connection takes a while, |
13 |
the user sees that rather than having Portage wait silently. |
14 |
|
15 |
Bug: https://bugs.gentoo.org/697566 |
16 |
Signed-off-by: Michał Górny <mgorny@g.o> |
17 |
--- |
18 |
lib/portage/package/ebuild/fetch.py | 36 +++++++++++++++-------------- |
19 |
1 file changed, 19 insertions(+), 17 deletions(-) |
20 |
|
21 |
diff --git a/lib/portage/package/ebuild/fetch.py b/lib/portage/package/ebuild/fetch.py |
22 |
index debab38a2..599c496ee 100644 |
23 |
--- a/lib/portage/package/ebuild/fetch.py |
24 |
+++ b/lib/portage/package/ebuild/fetch.py |
25 |
@@ -382,7 +382,7 @@ class MirrorLayoutConfig(object): |
26 |
return ret |
27 |
|
28 |
|
29 |
-def get_mirror_url(mirror_url, filename, cache_path=None): |
30 |
+def get_mirror_url(mirror_url, filename, mysettings, cache_path=None): |
31 |
""" |
32 |
Get correct fetch URL for a given file, accounting for mirror |
33 |
layout configuration. |
34 |
@@ -408,23 +408,25 @@ def get_mirror_url(mirror_url, filename, cache_path=None): |
35 |
if ts >= time.time() - 86400: |
36 |
mirror_conf.deserialize(data) |
37 |
else: |
38 |
+ tmpfile = '.layout.conf.%d' % time.time() |
39 |
try: |
40 |
- f = urlopen(mirror_url + '/distfiles/layout.conf') |
41 |
- try: |
42 |
- data = io.StringIO(f.read().decode('utf8')) |
43 |
- finally: |
44 |
- f.close() |
45 |
- |
46 |
- mirror_conf.read_from_file(data) |
47 |
+ if fetch({tmpfile: (mirror_url + '/distfiles/layout.conf',)}, |
48 |
+ mysettings, fetchonly=1, try_mirrors=0): |
49 |
+ tmpfile = os.path.join(mysettings['DISTDIR'], tmpfile) |
50 |
+ try: |
51 |
+ mirror_conf.read_from_file(tmpfile) |
52 |
+ finally: |
53 |
+ os.unlink(tmpfile) |
54 |
+ else: |
55 |
+ raise IOError() |
56 |
except (ConfigParserError, IOError, UnicodeDecodeError): |
57 |
- # Do not cache negative results. |
58 |
- cache_path = None |
59 |
- |
60 |
- cache[mirror_url] = (time.time(), mirror_conf.serialize()) |
61 |
- if cache_path is not None: |
62 |
- f = atomic_ofstream(cache_path, 'w') |
63 |
- json.dump(cache, f) |
64 |
- f.close() |
65 |
+ pass |
66 |
+ else: |
67 |
+ cache[mirror_url] = (time.time(), mirror_conf.serialize()) |
68 |
+ if cache_path is not None: |
69 |
+ f = atomic_ofstream(cache_path, 'w') |
70 |
+ json.dump(cache, f) |
71 |
+ f.close() |
72 |
|
73 |
return (mirror_url + "/distfiles/" + |
74 |
mirror_conf.get_best_supported_layout().get_path(filename)) |
75 |
@@ -619,7 +621,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, |
76 |
mirror_cache = None |
77 |
for l in locations: |
78 |
filedict[myfile].append(functools.partial( |
79 |
- get_mirror_url, l, myfile, mirror_cache)) |
80 |
+ get_mirror_url, l, myfile, mysettings, mirror_cache)) |
81 |
if myuri is None: |
82 |
continue |
83 |
if myuri[:9]=="mirror://": |
84 |
-- |
85 |
2.23.0 |