commit:     af0d91e9a251cb6ecf2568c51b21e6072e8c5241
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Wed May 12 21:37:56 2021 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon May 24 04:56:02 2021 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=af0d91e9

Refactor fetch() for selective restrictions

Refactor the fetch() function so that fetch/mirror restrictions only
affect the code per-URI rather than globally.  This will make it easier
to apply restrictions selectively in EAPI 8.

Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/portage/package/ebuild/fetch.py | 54 ++++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 28 deletions(-)

diff --git a/lib/portage/package/ebuild/fetch.py 
b/lib/portage/package/ebuild/fetch.py
index 73abec595..2f3111b65 100644
--- a/lib/portage/package/ebuild/fetch.py
+++ b/lib/portage/package/ebuild/fetch.py
@@ -813,8 +813,6 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
        custommirrors = grabdict(os.path.join(mysettings["PORTAGE_CONFIGROOT"],
                CUSTOM_MIRRORS_FILE), recursive=1)
 
-       mymirrors=[]
-
        if listonly or ("distlocks" not in features):
                use_locks = 0
 
@@ -832,16 +830,22 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
                                "FEATURES in /etc/portage/make.conf\n"), 
noiselevel=-1)
 #                      use_locks = 0
 
-       # local mirrors are always added
-       if try_mirrors and "local" in custommirrors:
-               mymirrors += custommirrors["local"]
-
-       if restrict_mirror:
-               # We don't add any mirrors.
-               pass
-       else:
-               if try_mirrors:
-                       mymirrors += [x.rstrip("/") for x in 
mysettings["GENTOO_MIRRORS"].split() if x]
+       local_mirrors = []
+       public_mirrors = []
+       fsmirrors = []
+       if try_mirrors:
+               for x in custommirrors.get("local", []):
+                       if x.startswith("/"):
+                               fsmirrors.append(x)
+                       else:
+                               local_mirrors.append(x)
+               for x in mysettings["GENTOO_MIRRORS"].split():
+                       if not x:
+                               continue
+                       if x.startswith('/'):
+                               fsmirrors.append(x.rstrip("/"))
+                       else:
+                               public_mirrors.append(x.rstrip("/"))
 
        hash_filter = _hash_filter(mysettings.get("PORTAGE_CHECKSUM_FILTER", 
""))
        if hash_filter.transparent:
@@ -864,23 +868,8 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
                shlex_split(mysettings.get("PORTAGE_RO_DISTDIRS", "")) \
                if os.path.isdir(x)]
 
-       fsmirrors = []
-       for x in range(len(mymirrors)-1,-1,-1):
-               if mymirrors[x] and mymirrors[x][0]=='/':
-                       fsmirrors += [mymirrors[x]]
-                       del mymirrors[x]
-
        restrict_fetch = "fetch" in restrict
        force_mirror = "force-mirror" in features and not restrict_mirror
-       custom_local_mirrors = custommirrors.get("local", [])
-       if restrict_fetch:
-               # With fetch restriction, a normal uri may only be fetched from
-               # custom local mirrors (if available).  A mirror:// uri may also
-               # be fetched from specific mirrors (effectively overriding fetch
-               # restriction, but only for specific mirrors).
-               locations = custom_local_mirrors
-       else:
-               locations = mymirrors
 
        file_uri_tuples = []
        # Check for 'items' attribute since OrderedDict is not a dict.
@@ -916,7 +905,16 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
                                                ".mirror-cache.json")
                        else:
                                mirror_cache = None
-                       for l in locations:
+
+                       # With fetch restriction, a normal uri may only be 
fetched from
+                       # custom local mirrors (if available).  A mirror:// uri 
may also
+                       # be fetched from specific mirrors (effectively 
overriding fetch
+                       # restriction, but only for specific mirrors).
+                       location_lists = [local_mirrors]
+                       if not restrict_fetch and not restrict_mirror:
+                               location_lists.append(public_mirrors)
+
+                       for l in itertools.chain(*location_lists):
                                filedict[myfile].append(functools.partial(
                                        get_mirror_url, l, myfile, mysettings, 
mirror_cache))
                if myuri is None:

Reply via email to