public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Zac Medico <zmedico@gentoo.org>
To: Mike Gilbert <floppym@gentoo.org>, Zac Medico <zmedico@gentoo.org>
Cc: gentoo-portage-dev@lists.gentoo.org
Subject: Re: [gentoo-portage-dev] [PATCH] Improve handling of percent-signs in SRC_URI
Date: Sun, 31 May 2020 16:11:28 -0700	[thread overview]
Message-ID: <3697840e-d944-72e8-ead5-9564d1c1b47f@gentoo.org> (raw)
In-Reply-To: <CAJ0EP43QfFp3hztYac0CSYOX7+MatSKYW=DDhd6UZb1iLJyJwA@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 4328 bytes --]

On 5/31/20 1:53 PM, Mike Gilbert wrote:
> On Sun, May 31, 2020 at 2:01 PM Zac Medico <zmedico@gentoo.org> wrote:
>>
>> On 5/31/20 6:17 AM, Mike Gilbert wrote:
>>> Unquote the URL basename when fetching from upstream.
>>> Quote the filename when fetching from mirrors.
>>>
>>> Bug: https://bugs.gentoo.org/719810
>>> Signed-off-by: Mike Gilbert <floppym@gentoo.org>
>>> ---
>>>  lib/portage/dbapi/porttree.py       | 7 ++++++-
>>>  lib/portage/package/ebuild/fetch.py | 9 +++++++--
>>>  2 files changed, 13 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/lib/portage/dbapi/porttree.py b/lib/portage/dbapi/porttree.py
>>> index 08af17bcd..984263039 100644
>>> --- a/lib/portage/dbapi/porttree.py
>>> +++ b/lib/portage/dbapi/porttree.py
>>> @@ -55,6 +55,11 @@ try:
>>>  except ImportError:
>>>       from urlparse import urlparse
>>>
>>> +try:
>>> +     from urllib.parse import unquote as urlunquote
>>> +except ImportError:
>>> +     from urllib import unquote as urlunquote
>>> +
>>>  if sys.hexversion >= 0x3000000:
>>>       # pylint: disable=W0622
>>>       basestring = str
>>> @@ -1547,7 +1552,7 @@ def _parse_uri_map(cpv, metadata, use=None):
>>>                       myuris.pop()
>>>                       distfile = myuris.pop()
>>>               else:
>>> -                     distfile = os.path.basename(uri)
>>> +                     distfile = urlunquote(os.path.basename(uri))
>>>                       if not distfile:
>>>                               raise portage.exception.InvalidDependString(
>>>                                       ("getFetchMap(): '%s' SRC_URI has no file " + \
>>> diff --git a/lib/portage/package/ebuild/fetch.py b/lib/portage/package/ebuild/fetch.py
>>> index 28e7caf53..47c3ad28f 100644
>>> --- a/lib/portage/package/ebuild/fetch.py
>>> +++ b/lib/portage/package/ebuild/fetch.py
>>> @@ -26,6 +26,11 @@ try:
>>>  except ImportError:
>>>       from urlparse import urlparse
>>>
>>> +try:
>>> +     from urllib.parse import quote as urlquote
>>> +except ImportError:
>>> +     from urllib import quote as urlquote
>>> +
>>>  import portage
>>>  portage.proxy.lazyimport.lazyimport(globals(),
>>>       'portage.package.ebuild.config:check_config_instance,config',
>>> @@ -351,7 +356,7 @@ _size_suffix_map = {
>>>
>>>  class FlatLayout(object):
>>>       def get_path(self, filename):
>>> -             return filename
>>> +             return urlquote(filename)
>>>
>>>       def get_filenames(self, distdir):
>>>               for dirpath, dirnames, filenames in os.walk(distdir,
>>> @@ -382,7 +387,7 @@ class FilenameHashLayout(object):
>>>                       c = c // 4
>>>                       ret += fnhash[:c] + '/'
>>>                       fnhash = fnhash[c:]
>>> -             return ret + filename
>>> +             return ret + urlquote(filename)
>>>
>>>       def get_filenames(self, distdir):
>>>               pattern = ''
>>>
>>
>> We've also got these other basename calls in fetch.py:
>>
>>> diff --git a/lib/portage/package/ebuild/fetch.py b/lib/portage/package/ebuild/fetch.py
>>> index 28e7caf53..56b375d58 100644
>>> --- a/lib/portage/package/ebuild/fetch.py
>>> +++ b/lib/portage/package/ebuild/fetch.py
>>> @@ -730,9 +730,9 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
>>>         else:
>>>                 for myuri in myuris:
>>>                         if urlparse(myuri).scheme:
>>> -                               file_uri_tuples.append((os.path.basename(myuri), myuri))
>>> +                               file_uri_tuples.append((urlunquote(os.path.basename(myuri)), myuri))
>>>                         else:
>>> -                               file_uri_tuples.append((os.path.basename(myuri), None))
>>> +                               file_uri_tuples.append((urlunquote(os.path.basename(myuri)), None))
> 
> I'm not sure how to reach this particular code path. In my testing,
> the fetch() function gets passed an OrderedDict in myuris, and the
> filenames have already been unquoted, so we don't want to do it again.
> 
> Any idea how this "else" block would ever be executed?

This code is only for backward compatibility code, so we should probably
add a deprecation warning and forget about quoting/unquoting.
-- 
Thanks,
Zac


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 981 bytes --]

      reply	other threads:[~2020-05-31 23:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-31 13:17 [gentoo-portage-dev] [PATCH] Improve handling of percent-signs in SRC_URI Mike Gilbert
2020-05-31 14:11 ` [gentoo-portage-dev] " Mike Gilbert
2020-05-31 18:01 ` [gentoo-portage-dev] " Zac Medico
2020-05-31 19:21   ` Mike Gilbert
2020-05-31 19:36     ` Zac Medico
2020-05-31 19:51       ` Mike Gilbert
2020-05-31 20:13         ` Zac Medico
2020-05-31 20:24   ` Ulrich Mueller
2020-05-31 20:32     ` Zac Medico
2020-05-31 20:36       ` Mike Gilbert
2020-05-31 20:53   ` Mike Gilbert
2020-05-31 23:11     ` Zac Medico [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3697840e-d944-72e8-ead5-9564d1c1b47f@gentoo.org \
    --to=zmedico@gentoo.org \
    --cc=floppym@gentoo.org \
    --cc=gentoo-portage-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox