fetch: correctly handle file name without scheme
authorZac Medico <zmedico@gentoo.org>
Fri, 24 May 2013 00:06:32 +0000 (17:06 -0700)
committerZac Medico <zmedico@gentoo.org>
Fri, 24 May 2013 00:06:32 +0000 (17:06 -0700)
Before, the file name would be passed directly to FETCHCOMMAND as
though it were a valid URI. Now, FETCHCOMMAND will only be called when
there is a valid URI or a mirror to try.

pym/portage/dbapi/porttree.py
pym/portage/package/ebuild/fetch.py

index 77f633f75e9e6011db2ed3ba3f499d957c52363d..a2082a37281ece65b55e99ebe86784eaeae8eb8d 100644 (file)
@@ -44,6 +44,11 @@ import sys
 import traceback
 import warnings
 
+try:
+       from urllib.parse import urlparse
+except ImportError:
+       from urlparse import urlparse
+
 if sys.hexversion >= 0x3000000:
        basestring = str
        long = int
@@ -1164,7 +1169,11 @@ def _parse_uri_map(cpv, metadata, use=None):
                        # while ensuring uniqueness.
                        uri_set = OrderedDict()
                        uri_map[distfile] = uri_set
-               uri_set[uri] = True
+
+               # SRC_URI may contain a file name with no scheme, and in
+               # this case it does not belong in uri_set.
+               if urlparse(uri).scheme:
+                       uri_set[uri] = True
 
        # Convert OrderedDicts to tuples.
        for k, v in uri_map.items():
index 162c7c274fdd8daf6e0f35143f1d82e53d07d3c6..50a1b7216e134124a429426b8f8421e0632e485f 100644 (file)
@@ -14,6 +14,10 @@ import stat
 import sys
 import tempfile
 
+try:
+       from urllib.parse import urlparse
+except ImportError:
+       from urlparse import urlparse
 
 import portage
 portage.proxy.lazyimport.lazyimport(globals(),
@@ -402,9 +406,14 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
                for myfile, uri_set in myuris.items():
                        for myuri in uri_set:
                                file_uri_tuples.append((myfile, myuri))
+                       if not uri_set:
+                               file_uri_tuples.append((myfile, None))
        else:
                for myuri in myuris:
-                       file_uri_tuples.append((os.path.basename(myuri), myuri))
+                       if urlparse(myuri).scheme:
+                               file_uri_tuples.append((os.path.basename(myuri), myuri))
+                       else:
+                               file_uri_tuples.append((os.path.basename(myuri), None))
 
        filedict = OrderedDict()
        primaryuri_dict = {}
@@ -414,6 +423,8 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
                        filedict[myfile]=[]
                        for y in range(0,len(locations)):
                                filedict[myfile].append(locations[y]+"/distfiles/"+myfile)
+               if myuri is None:
+                       continue
                if myuri[:9]=="mirror://":
                        eidx = myuri.find("/", 9)
                        if eidx != -1: