From ed0e1f07de9e3f52f20c29c0d2e34de5f9ba9cce Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Tue, 18 Mar 2008 13:53:38 +0000 Subject: create _pick_one_ (needed for next commit) --- urpm/mirrors.pm | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/urpm/mirrors.pm b/urpm/mirrors.pm index 1a671caa..8d39c897 100644 --- a/urpm/mirrors.pm +++ b/urpm/mirrors.pm @@ -43,6 +43,18 @@ sub pick_one { sub _pick_one { my ($urpm, $mirrorlist, $must_succeed, $allow_cache_update) = @_; + my $url; + if (my $cache = _pick_one_($urpm, $mirrorlist, $allow_cache_update)) { + $url = $cache->{chosen}; + } + !$url && $must_succeed and $urpm->{fatal}(10, N("Could not find a mirror from mirrorlist %s", $mirrorlist)); + $url; +} + +#- side-effects: $urpm->{mirrors_cache} +sub _pick_one_ { + my ($urpm, $mirrorlist, $allow_cache_update) = @_; + my $cache = _cache__may_clean_if_outdated($urpm, $mirrorlist, $allow_cache_update); if (!$cache->{chosen}) { @@ -51,10 +63,7 @@ sub _pick_one { $cache->{time} = time(); } - $cache->{chosen} = $cache->{list}[0]{url} or do { - $must_succeed and $urpm->{fatal}(10, N("Could not find a mirror from mirrorlist %s", $mirrorlist)); - return; - }; + $cache->{chosen} = $cache->{list}[0]{url} or return; _save_cache($urpm); } if ($cache->{nb_uses}++) { @@ -63,7 +72,7 @@ sub _pick_one { $urpm->{log}("using mirror $cache->{chosen}"); } - $cache->{chosen}; + $cache; } #- side-effects: $urpm->{mirrors_cache} sub black_list { -- cgit v1.2.1