Gentoo Archives: gentoo-portage-dev

From: Mike Gilbert <floppym@g.o>
To: 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 19:21:18
Message-Id: CAJ0EP40_KVAkdXyqMWQtKTEVYOAA7549=O3XuoKb-4ej_KYgbQ@mail.gmail.com
In Reply to: Re: [gentoo-portage-dev] [PATCH] Improve handling of percent-signs in SRC_URI by Zac Medico
1 On Sun, May 31, 2020 at 2:01 PM Zac Medico <zmedico@g.o> wrote:
2 >
3 > On 5/31/20 6:17 AM, Mike Gilbert wrote:
4 > > Unquote the URL basename when fetching from upstream.
5 > > Quote the filename when fetching from mirrors.
6 > >
7 > > Bug: https://bugs.gentoo.org/719810
8 > > Signed-off-by: Mike Gilbert <floppym@g.o>
9 > > ---
10 > > lib/portage/dbapi/porttree.py | 7 ++++++-
11 > > lib/portage/package/ebuild/fetch.py | 9 +++++++--
12 > > 2 files changed, 13 insertions(+), 3 deletions(-)
13 > >
14 > > diff --git a/lib/portage/dbapi/porttree.py b/lib/portage/dbapi/porttree.py
15 > > index 08af17bcd..984263039 100644
16 > > --- a/lib/portage/dbapi/porttree.py
17 > > +++ b/lib/portage/dbapi/porttree.py
18 > > @@ -55,6 +55,11 @@ try:
19 > > except ImportError:
20 > > from urlparse import urlparse
21 > >
22 > > +try:
23 > > + from urllib.parse import unquote as urlunquote
24 > > +except ImportError:
25 > > + from urllib import unquote as urlunquote
26 > > +
27 > > if sys.hexversion >= 0x3000000:
28 > > # pylint: disable=W0622
29 > > basestring = str
30 > > @@ -1547,7 +1552,7 @@ def _parse_uri_map(cpv, metadata, use=None):
31 > > myuris.pop()
32 > > distfile = myuris.pop()
33 > > else:
34 > > - distfile = os.path.basename(uri)
35 > > + distfile = urlunquote(os.path.basename(uri))
36 > > if not distfile:
37 > > raise portage.exception.InvalidDependString(
38 > > ("getFetchMap(): '%s' SRC_URI has no file " + \
39 > > diff --git a/lib/portage/package/ebuild/fetch.py b/lib/portage/package/ebuild/fetch.py
40 > > index 28e7caf53..47c3ad28f 100644
41 > > --- a/lib/portage/package/ebuild/fetch.py
42 > > +++ b/lib/portage/package/ebuild/fetch.py
43 > > @@ -26,6 +26,11 @@ try:
44 > > except ImportError:
45 > > from urlparse import urlparse
46 > >
47 > > +try:
48 > > + from urllib.parse import quote as urlquote
49 > > +except ImportError:
50 > > + from urllib import quote as urlquote
51 > > +
52 > > import portage
53 > > portage.proxy.lazyimport.lazyimport(globals(),
54 > > 'portage.package.ebuild.config:check_config_instance,config',
55 > > @@ -351,7 +356,7 @@ _size_suffix_map = {
56 > >
57 > > class FlatLayout(object):
58 > > def get_path(self, filename):
59 > > - return filename
60 > > + return urlquote(filename)
61 > >
62 > > def get_filenames(self, distdir):
63 > > for dirpath, dirnames, filenames in os.walk(distdir,
64 > > @@ -382,7 +387,7 @@ class FilenameHashLayout(object):
65 > > c = c // 4
66 > > ret += fnhash[:c] + '/'
67 > > fnhash = fnhash[c:]
68 > > - return ret + filename
69 > > + return ret + urlquote(filename)
70 > >
71 > > def get_filenames(self, distdir):
72 > > pattern = ''
73 > >
74 >
75 > We've also got these other basename calls in fetch.py:
76 >
77 > > diff --git a/lib/portage/package/ebuild/fetch.py b/lib/portage/package/ebuild/fetch.py
78 > > index 28e7caf53..56b375d58 100644
79 > > --- a/lib/portage/package/ebuild/fetch.py
80 > > +++ b/lib/portage/package/ebuild/fetch.py
81 > > @@ -730,9 +730,9 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
82 > > else:
83 > > for myuri in myuris:
84 > > if urlparse(myuri).scheme:
85 > > - file_uri_tuples.append((os.path.basename(myuri), myuri))
86 > > + file_uri_tuples.append((urlunquote(os.path.basename(myuri)), myuri))
87 > > else:
88 > > - file_uri_tuples.append((os.path.basename(myuri), None))
89 > > + file_uri_tuples.append((urlunquote(os.path.basename(myuri)), None))
90 >
91 > The case with no scheme is not a URI, so we need to decide whether
92 > or not to unquote, and we should make _parse_uri_map behavior
93 > consistent for this case.
94
95 Backing up, I think unquoting the basename is really a separate issue
96 from quoting the filename in Layout.get_path(). The latter fixes a
97 known bug when fetching from mirrors, whereas the former seems like a
98 cosmetic issue. I don't think we should mix these two up into the same
99 commit.
100
101 Could I get your approval to push my original patch (Escape
102 percent-signs in filename when fetching from mirrors)?

Replies