Fix region handling of broken mirrors
authorMichael Prokop <mika@grml.org>
Thu, 12 May 2022 10:54:09 +0000 (12:54 +0200)
committerMichael Prokop <mika@grml.org>
Thu, 12 May 2022 10:54:09 +0000 (12:54 +0200)
The handling of region vs broken mirrors (in state "f") is wrong,
and we might end up with the wrong URLs in foreign regions, like:

| # ./generate_mirror_map| sort -u
| at mirror.alwyzon.net/grml/|at.mirror.anexia.com/grml/
| br grml.c3sl.ufpr.br//
| ch mirror.de.leaseweb.net/grml/|ftp.halifax.rwth-aachen.de/grml/|mirror.23m.com/grml/
| cn mirror.de.leaseweb.net/grml/|ftp.halifax.rwth-aachen.de/grml/|mirror.23m.com/grml/
| de mirror.de.leaseweb.net/grml/|ftp.halifax.rwth-aachen.de/grml/|mirror.23m.com/grml/
| fi mirror.de.leaseweb.net/grml/|ftp.halifax.rwth-aachen.de/grml/|mirror.23m.com/grml/
| gb mirror.bytemark.co.uk/grml/
| hk mirror-hk.koddos.net/grml/
| ir mirror.bardia.tech/grml/
| nl mirror.koddos.net/grml/|mirror.nl.leaseweb.net/grml/
| tw tw1.mirror.blendbyte.net/grml/
| ua grml.ip-connect.info//|grml.ip-connect.vn.ua//
| us mirror.us.leaseweb.net/grml/|mirrors.rit.edu/grml/

Now with the fixed behavior, we get what we're expecting:

| # ./generate_mirror_map| sort -u
| at mirror.alwyzon.net/grml/|at.mirror.anexia.com/grml/
| br grml.c3sl.ufpr.br//
| de mirror.23m.com/grml/|mirror.de.leaseweb.net/grml/|ftp.halifax.rwth-aachen.de/grml/
| gb mirror.bytemark.co.uk/grml/
| hk mirror-hk.koddos.net/grml/
| ir mirror.bardia.tech/grml/
| nl mirror.nl.leaseweb.net/grml/|mirror.koddos.net/grml/
| tw tw1.mirror.blendbyte.net/grml/
| ua grml.ip-connect.info//|grml.ip-connect.vn.ua//
| us mirror.us.leaseweb.net/grml/|mirrors.rit.edu/grml/

bin/generate_mirror_map

index 6d37e1b..d41107c 100755 (executable)
@@ -17,9 +17,9 @@ foreach my $url ( keys %{$state} ) {
        $mirror = $state -> { $url } ; # a Mirmon::Mirror object
        my ($time, $history) = split('-', $mirror->{state_history});
        my $last_state = substr($history,-1,1);
+       next if $last_state eq 'f';
        my $region = $mirror->region;
        $regions_hash->{$region} = 1;
-       next if $last_state eq 'f';
        $mirrors->{ $region } ||= [];
        $url =~ s/^http:\/\///;
        push @{$mirrors->{ $region }}, $url;