diff options
Diffstat (limited to 'perl-install/mirror.pm')
| -rw-r--r-- | perl-install/mirror.pm | 98 |
1 files changed, 78 insertions, 20 deletions
diff --git a/perl-install/mirror.pm b/perl-install/mirror.pm index 68684b99a..654bdb2e9 100644 --- a/perl-install/mirror.pm +++ b/perl-install/mirror.pm @@ -1,4 +1,4 @@ -package mirror; # $Id: mirror.pm 269985 2010-06-09 22:02:57Z herton $ +package mirror; use diagnostics; use strict; @@ -7,6 +7,16 @@ use feature 'state'; use common; use log; +=head1 SYNOPSYS + +B<mirror> enables to manage Mageia distribution mirrors + +=head1 Functions + +=over + +=cut + my %land2tzs = ( N_("Australia") => [ 'Australia/Sydney' ], N_("Austria") => [ 'Europe/Vienna', 'Europe/Brussels', 'Europe/Berlin' ], @@ -42,17 +52,63 @@ my %land2tzs = ( N_("United States") => [ 'America/New_York', 'Canada/Atlantic', 'Asia/Tokyo', 'Australia/Sydney', 'Europe/Paris' ], ); +=item mirror2text($mirror) + +Returns a displayable string from a mirror struct + +=cut + sub mirror2text { my ($mirror) = @_; translate($mirror->{country}) . '|' . $mirror->{host} . ($mirror->{method} ? " ($mirror->{method})" : ''); } +=item register_downloader($func) + +Sets a downloader program + +=cut + my $downloader; sub register_downloader { my ($func) = @_; $downloader = $func; } +sub _mirrors_raw_install { + my ($list) = @_; + require install::http; + my $f = install::http::getFile($list, "strict-certificate-check" => 1) or die "mirror list not found"; + local $SIG{ALRM} = sub { die "timeout" }; + alarm 60; + log::l("using mirror list $list"); + my @lines; + push @lines, $_ while <$f>; + alarm 0; + @lines; +} + +sub _mirrors_raw_standalone { + my ($list) = @_; + my @lines; + if (ref($downloader)) { + @lines = $downloader->($list); + @lines or die "mirror list not found"; + } else { + die "Missing download callback"; + } + @lines; +} + +=item mirrors_raw($product_id) + +Returns a list of mirrors hash refs from http://mirrors.mageia.org + +Note that in standalone mode, one has to actually use register_downloader() +first in order to provide a downloader callback. + +=cut + sub mirrors_raw { my ($product_id) = @_; @@ -62,27 +118,19 @@ sub mirrors_raw { #- FIXME! (blino) we use use https here my $list = "http://mirrors.mageia.org/api/$type.$product_id->{version}.$product_id->{arch}.list?product=$product_id->{product}"; log::explanations("trying mirror list from $list"); - my @lines; - if ($::isInstall) { - require install::http; - my $f = install::http::getFile($list, "strict-certificate-check" => 1) or die "mirror list not found"; - local $SIG{ALRM} = sub { die "timeout" }; - alarm 60; - log::l("using mirror list $list"); - push @lines, $_ while <$f>; - install::http::close(); - alarm 0; - } else { - if (ref($downloader)) { - @lines = $downloader->($list); - @lines or die "mirror list not found"; - } else { - die "Missing download callback"; - } - } + my @lines = $::isInstall ? _mirrors_raw_install($list) : _mirrors_raw_standalone($list); map { common::parse_LDAP_namespace_structure(chomp_($_)) } @lines; } +=item list($product_id, $type) + + +Returns a list of mirrors hash refs as returned by mirrors_raw() but filters it. + +One can select the type of mirrors ('distrib', 'updates', ...) or 'all' + +=cut + sub list { my ($product_id, $type) = @_; @@ -98,12 +146,18 @@ sub list { my @mirrors = grep { ($_->{method}, $_->{host}, $_->{dir}) = $_->{url} =~ m!^(ftp|http)://(.*?)(/.*)!; - $_->{method} && ($type eq 'all' || $_->{type} eq $type); + $_->{method} && (member($type, 'all', $_->{type})); } @mirrors_raw or log::explanations("no mirrors of type $type"), return; @mirrors && \@mirrors; } +=item nearest($timezone, $mirrors) + +Randomly returns one of the nearest mirror + +=cut + sub nearest { my ($timezone, $mirrors) = @_; @@ -120,4 +174,8 @@ sub nearest { $possible[rand @possible]; } +=back + +=cut + 1; |
