Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: Mike Gilbert <floppym@g.o>, Zac Medico <zmedico@g.o>
Cc: gentoo-portage-dev@l.g.o
Subject: Re: [gentoo-portage-dev] [PATCH] Improve handling of percent-signs in SRC_URI
Date: Sun, 31 May 2020 23:11:33
Message-Id: 3697840e-d944-72e8-ead5-9564d1c1b47f@gentoo.org
In Reply to: Re: [gentoo-portage-dev] [PATCH] Improve handling of percent-signs in SRC_URI by Mike Gilbert
1 On 5/31/20 1:53 PM, Mike Gilbert wrote:
2 > On Sun, May 31, 2020 at 2:01 PM Zac Medico <zmedico@g.o> wrote:
3 >>
4 >> On 5/31/20 6:17 AM, Mike Gilbert wrote:
5 >>> Unquote the URL basename when fetching from upstream.
6 >>> Quote the filename when fetching from mirrors.
7 >>>
8 >>> Bug: https://bugs.gentoo.org/719810
9 >>> Signed-off-by: Mike Gilbert <floppym@g.o>
10 >>> ---
11 >>> lib/portage/dbapi/porttree.py | 7 ++++++-
12 >>> lib/portage/package/ebuild/fetch.py | 9 +++++++--
13 >>> 2 files changed, 13 insertions(+), 3 deletions(-)
14 >>>
15 >>> diff --git a/lib/portage/dbapi/porttree.py b/lib/portage/dbapi/porttree.py
16 >>> index 08af17bcd..984263039 100644
17 >>> --- a/lib/portage/dbapi/porttree.py
18 >>> +++ b/lib/portage/dbapi/porttree.py
19 >>> @@ -55,6 +55,11 @@ try:
20 >>> except ImportError:
21 >>> from urlparse import urlparse
22 >>>
23 >>> +try:
24 >>> + from urllib.parse import unquote as urlunquote
25 >>> +except ImportError:
26 >>> + from urllib import unquote as urlunquote
27 >>> +
28 >>> if sys.hexversion >= 0x3000000:
29 >>> # pylint: disable=W0622
30 >>> basestring = str
31 >>> @@ -1547,7 +1552,7 @@ def _parse_uri_map(cpv, metadata, use=None):
32 >>> myuris.pop()
33 >>> distfile = myuris.pop()
34 >>> else:
35 >>> - distfile = os.path.basename(uri)
36 >>> + distfile = urlunquote(os.path.basename(uri))
37 >>> if not distfile:
38 >>> raise portage.exception.InvalidDependString(
39 >>> ("getFetchMap(): '%s' SRC_URI has no file " + \
40 >>> diff --git a/lib/portage/package/ebuild/fetch.py b/lib/portage/package/ebuild/fetch.py
41 >>> index 28e7caf53..47c3ad28f 100644
42 >>> --- a/lib/portage/package/ebuild/fetch.py
43 >>> +++ b/lib/portage/package/ebuild/fetch.py
44 >>> @@ -26,6 +26,11 @@ try:
45 >>> except ImportError:
46 >>> from urlparse import urlparse
47 >>>
48 >>> +try:
49 >>> + from urllib.parse import quote as urlquote
50 >>> +except ImportError:
51 >>> + from urllib import quote as urlquote
52 >>> +
53 >>> import portage
54 >>> portage.proxy.lazyimport.lazyimport(globals(),
55 >>> 'portage.package.ebuild.config:check_config_instance,config',
56 >>> @@ -351,7 +356,7 @@ _size_suffix_map = {
57 >>>
58 >>> class FlatLayout(object):
59 >>> def get_path(self, filename):
60 >>> - return filename
61 >>> + return urlquote(filename)
62 >>>
63 >>> def get_filenames(self, distdir):
64 >>> for dirpath, dirnames, filenames in os.walk(distdir,
65 >>> @@ -382,7 +387,7 @@ class FilenameHashLayout(object):
66 >>> c = c // 4
67 >>> ret += fnhash[:c] + '/'
68 >>> fnhash = fnhash[c:]
69 >>> - return ret + filename
70 >>> + return ret + urlquote(filename)
71 >>>
72 >>> def get_filenames(self, distdir):
73 >>> pattern = ''
74 >>>
75 >>
76 >> We've also got these other basename calls in fetch.py:
77 >>
78 >>> diff --git a/lib/portage/package/ebuild/fetch.py b/lib/portage/package/ebuild/fetch.py
79 >>> index 28e7caf53..56b375d58 100644
80 >>> --- a/lib/portage/package/ebuild/fetch.py
81 >>> +++ b/lib/portage/package/ebuild/fetch.py
82 >>> @@ -730,9 +730,9 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
83 >>> else:
84 >>> for myuri in myuris:
85 >>> if urlparse(myuri).scheme:
86 >>> - file_uri_tuples.append((os.path.basename(myuri), myuri))
87 >>> + file_uri_tuples.append((urlunquote(os.path.basename(myuri)), myuri))
88 >>> else:
89 >>> - file_uri_tuples.append((os.path.basename(myuri), None))
90 >>> + file_uri_tuples.append((urlunquote(os.path.basename(myuri)), None))
91 >
92 > I'm not sure how to reach this particular code path. In my testing,
93 > the fetch() function gets passed an OrderedDict in myuris, and the
94 > filenames have already been unquoted, so we don't want to do it again.
95 >
96 > Any idea how this "else" block would ever be executed?
97
98 This code is only for backward compatibility code, so we should probably
99 add a deprecation warning and forget about quoting/unquoting.
100 --
101 Thanks,
102 Zac

Attachments

File name MIME type
signature.asc application/pgp-signature