Skip to content

Commit

Permalink
Merge branch 'fix_blacklist_base_miror'
Browse files Browse the repository at this point in the history
  • Loading branch information
martin68 committed Nov 28, 2019
2 parents 4d3ed0b + ee69ecc commit f6ecc19
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions apt_smart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,20 @@ def available_mirrors(self):
logger.info("Adding BASE_URL mirror:")
if self.distributor_id == 'debian': # For Debian, base_url typically is not in MIRRORS_URL,
# add it explicitly
base_url_prefix = self.backend.BASE_URL.split('dists/codename-updates/Release')[0]
base_url_prefix = self.backend.BASE_URL.split('/dists/codename-updates/Release')[0]
mirrors.add(CandidateMirror(mirror_url=base_url_prefix, updater=self))
elif self.distributor_id == 'ubuntu': # For Ubuntu, base_url is not in MIRRORS_URL for
# some countries e.g. US (found it in Travis CI), add it explicitly
base_url_prefix = self.backend.BASE_URL.split('dists/codename-security/Release')[0]
base_url_prefix = self.backend.BASE_URL.split('/dists/codename-security/Release')[0]
mirrors.add(CandidateMirror(mirror_url=base_url_prefix, updater=self))
elif self.distributor_id == 'linuxmint': # For Linux Mint, base_url typically is not in MIRRORS_URL,
# add it explicitly
base_url_prefix = self.backend.BASE_URL.split('dists/codename/Release')[0]
base_url_prefix = self.backend.BASE_URL.split('/dists/codename/Release')[0]
mirrors.add(CandidateMirror(mirror_url=base_url_prefix, updater=self))
logger.info(base_url_prefix)
for candidate in self.backend.discover_mirrors():
if any(fnmatch.fnmatch(candidate.mirror_url, pattern) for pattern in self.blacklist):
if any(fnmatch.fnmatch(candidate.mirror_url, pattern) for pattern in self.blacklist)\
and normalize_mirror_url(candidate.mirror_url) != base_url_prefix:
logger.warning("Ignoring blacklisted mirror %s.", candidate.mirror_url)
else:
candidate.updater = self
Expand Down Expand Up @@ -431,6 +432,10 @@ def ranked_mirrors(self):
raise Exception("It looks like all %s are unavailable!" % num_mirrors)
if all(c.is_updating for c in mirrors):
logger.warning("It looks like all %s are being updated?!", num_mirrors)
# blacklist BASE_URL mirror if matches blacklist pattern
if any(fnmatch.fnmatch(mapping[self.base_url].mirror_url, pattern) for pattern in self.blacklist):
logger.warning("Ignoring blacklisted BASE_URL mirror %s.", mapping[self.base_url].mirror_url)
mirrors.remove(mapping[self.base_url])
return sorted(mirrors, key=lambda c: c.sort_key, reverse=True)

@cached_property
Expand Down

0 comments on commit f6ecc19

Please sign in to comment.