1 |
On 5/31/20 6:17 AM, Mike Gilbert wrote: |
2 |
> Unquote the URL basename when fetching from upstream. |
3 |
> Quote the filename when fetching from mirrors. |
4 |
> |
5 |
> Bug: https://bugs.gentoo.org/719810 |
6 |
> Signed-off-by: Mike Gilbert <floppym@g.o> |
7 |
> --- |
8 |
> lib/portage/dbapi/porttree.py | 7 ++++++- |
9 |
> lib/portage/package/ebuild/fetch.py | 9 +++++++-- |
10 |
> 2 files changed, 13 insertions(+), 3 deletions(-) |
11 |
> |
12 |
> diff --git a/lib/portage/dbapi/porttree.py b/lib/portage/dbapi/porttree.py |
13 |
> index 08af17bcd..984263039 100644 |
14 |
> --- a/lib/portage/dbapi/porttree.py |
15 |
> +++ b/lib/portage/dbapi/porttree.py |
16 |
> @@ -55,6 +55,11 @@ try: |
17 |
> except ImportError: |
18 |
> from urlparse import urlparse |
19 |
> |
20 |
> +try: |
21 |
> + from urllib.parse import unquote as urlunquote |
22 |
> +except ImportError: |
23 |
> + from urllib import unquote as urlunquote |
24 |
> + |
25 |
> if sys.hexversion >= 0x3000000: |
26 |
> # pylint: disable=W0622 |
27 |
> basestring = str |
28 |
> @@ -1547,7 +1552,7 @@ def _parse_uri_map(cpv, metadata, use=None): |
29 |
> myuris.pop() |
30 |
> distfile = myuris.pop() |
31 |
> else: |
32 |
> - distfile = os.path.basename(uri) |
33 |
> + distfile = urlunquote(os.path.basename(uri)) |
34 |
> if not distfile: |
35 |
> raise portage.exception.InvalidDependString( |
36 |
> ("getFetchMap(): '%s' SRC_URI has no file " + \ |
37 |
> diff --git a/lib/portage/package/ebuild/fetch.py b/lib/portage/package/ebuild/fetch.py |
38 |
> index 28e7caf53..47c3ad28f 100644 |
39 |
> --- a/lib/portage/package/ebuild/fetch.py |
40 |
> +++ b/lib/portage/package/ebuild/fetch.py |
41 |
> @@ -26,6 +26,11 @@ try: |
42 |
> except ImportError: |
43 |
> from urlparse import urlparse |
44 |
> |
45 |
> +try: |
46 |
> + from urllib.parse import quote as urlquote |
47 |
> +except ImportError: |
48 |
> + from urllib import quote as urlquote |
49 |
> + |
50 |
> import portage |
51 |
> portage.proxy.lazyimport.lazyimport(globals(), |
52 |
> 'portage.package.ebuild.config:check_config_instance,config', |
53 |
> @@ -351,7 +356,7 @@ _size_suffix_map = { |
54 |
> |
55 |
> class FlatLayout(object): |
56 |
> def get_path(self, filename): |
57 |
> - return filename |
58 |
> + return urlquote(filename) |
59 |
> |
60 |
> def get_filenames(self, distdir): |
61 |
> for dirpath, dirnames, filenames in os.walk(distdir, |
62 |
> @@ -382,7 +387,7 @@ class FilenameHashLayout(object): |
63 |
> c = c // 4 |
64 |
> ret += fnhash[:c] + '/' |
65 |
> fnhash = fnhash[c:] |
66 |
> - return ret + filename |
67 |
> + return ret + urlquote(filename) |
68 |
> |
69 |
> def get_filenames(self, distdir): |
70 |
> pattern = '' |
71 |
> |
72 |
|
73 |
We've also got these other basename calls in fetch.py: |
74 |
|
75 |
> diff --git a/lib/portage/package/ebuild/fetch.py b/lib/portage/package/ebuild/fetch.py |
76 |
> index 28e7caf53..56b375d58 100644 |
77 |
> --- a/lib/portage/package/ebuild/fetch.py |
78 |
> +++ b/lib/portage/package/ebuild/fetch.py |
79 |
> @@ -730,9 +730,9 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, |
80 |
> else: |
81 |
> for myuri in myuris: |
82 |
> if urlparse(myuri).scheme: |
83 |
> - file_uri_tuples.append((os.path.basename(myuri), myuri)) |
84 |
> + file_uri_tuples.append((urlunquote(os.path.basename(myuri)), myuri)) |
85 |
> else: |
86 |
> - file_uri_tuples.append((os.path.basename(myuri), None)) |
87 |
> + file_uri_tuples.append((urlunquote(os.path.basename(myuri)), None)) |
88 |
|
89 |
The case with no scheme is not a URI, so we need to decide whether |
90 |
or not to unquote, and we should make _parse_uri_map behavior |
91 |
consistent for this case. |
92 |
|
93 |
> |
94 |
> filedict = OrderedDict() |
95 |
> primaryuri_dict = {} |
96 |
> @@ -1229,7 +1229,7 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, |
97 |
> "information about how to\n!!! correctly specify " |
98 |
> "FETCHCOMMAND and RESUMECOMMAND.\n"), |
99 |
> level=logging.ERROR, noiselevel=-1) |
100 |
> - if myfile != os.path.basename(loc): |
101 |
> + if myfile != urlunquote(os.path.basename(loc)): |
102 |
> return 0 |
103 |
> |
104 |
> if not can_fetch: |
105 |
|
106 |
|
107 |
-- |
108 |
Thanks, |
109 |
Zac |