Comment 6 for bug 1822712

Revision history for this message
Heinrich Schuchardt (xypron) wrote (last edit ):

Splitting above sources.list line results in:
['deb', '[', 'arch=riscv64', ']', 'http://ports.ubuntu.com/ubuntu-ports/', 'lunar', 'main', 'restricted']

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]