Method _get_primary_mirror_from_apt_sources() incorrectly assumes that if the second field in the line starts with '[' the next field is the mirror url. Instead the method should look for the matching ']'. The field after ']' is the mirror.
@staticmethod
def _get_primary_mirror_from_apt_sources(apt_sources): """Heuristically determine primary mirror from an apt sources.list."""
with open(apt_sources, encoding="utf-8") as f:
for line in f: fields = line.split()
if len(fields) >= 3 and fields[0] == "deb": if fields[1].startswith("["): # options given, mirror is in third field mirror_idx = 2 else: mirror_idx = 1 if fields[mirror_idx].startswith("http://") or fields[ mirror_idx ].startswith("https://"): return fields[mirror_idx]
Splitting above sources.list line results in: ports.ubuntu. com/ubuntu- ports/', 'lunar', 'main', 'restricted']
['deb', '[', 'arch=riscv64', ']', 'http://
Method _get_primary_ mirror_ from_apt_ sources( ) incorrectly assumes that if the second field in the line starts with '[' the next field is the mirror url. Instead the method should look for the matching ']'. The field after ']' is the mirror.
@staticmethod mirror_ from_apt_ sources( apt_sources) :
"""Heuristical ly determine primary mirror from an apt sources.list."""
fields = line.split()
if fields[ 1].startswith( "["):
# options given, mirror is in third field
mirror_ idx = 2
else:
mirror_ idx = 1
if fields[ mirror_ idx].startswith ("http://") or fields[
mirror_ idx
] .startswith( "https://"):
return fields[mirror_idx]
def _get_primary_
with open(apt_sources, encoding="utf-8") as f:
for line in f:
if len(fields) >= 3 and fields[0] == "deb":