summaryrefslogtreecommitdiffstats
path: root/urpm
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2006-11-28 10:01:08 +0000
committerPascal Rigaux <pixel@mandriva.com>2006-11-28 10:01:08 +0000
commite45ec0d2d69b5f3e438cc2aa7ca3bf715d7df57a (patch)
tree836d63c5fc4692ba980c0b9ceb8420394d1468af /urpm
parenteabc176287bd29cfd8f49b97937092297009ff67 (diff)
downloadurpmi-e45ec0d2d69b5f3e438cc2aa7ca3bf715d7df57a.tar
urpmi-e45ec0d2d69b5f3e438cc2aa7ca3bf715d7df57a.tar.gz
urpmi-e45ec0d2d69b5f3e438cc2aa7ca3bf715d7df57a.tar.bz2
urpmi-e45ec0d2d69b5f3e438cc2aa7ca3bf715d7df57a.tar.xz
urpmi-e45ec0d2d69b5f3e438cc2aa7ca3bf715d7df57a.zip
- factorize code from _update_medium__parse_if_unmodified__remote() to make it
similar to _update_medium__parse_if_unmodified__local() - rationalize error handling
Diffstat (limited to 'urpm')
-rw-r--r--urpm/media.pm81
1 files changed, 53 insertions, 28 deletions
diff --git a/urpm/media.pm b/urpm/media.pm
index a6c22286..27655d04 100644
--- a/urpm/media.pm
+++ b/urpm/media.pm
@@ -1190,6 +1190,20 @@ sub get_hdlist_or_synthesis__local {
0;
}
}
+sub get_hdlist_or_synthesis__remote {
+ my ($urpm, $medium, $callback, $quiet) = @_;
+
+ if (urpm::download::sync($urpm, $medium, [ _url_with_hdlist($medium) ],
+ quiet => $quiet, callback => $callback) &&
+ file_size(cachedir_with_hdlist($urpm, $medium)) >= 20) {
+ $urpm->{log}(N("...retrieving done"));
+ 1;
+ } else {
+ chomp(my $err = $@);
+ $urpm->{error}(N("...retrieving failed: %s", $err));
+ 0;
+ }
+}
sub get_hdlist_or_synthesis_and_check_md5sum__local {
my ($urpm, $medium, $retrieved_md5sum, $callback) = @_;
@@ -1205,6 +1219,19 @@ sub get_hdlist_or_synthesis_and_check_md5sum__local {
1;
}
+sub get_hdlist_or_synthesis_and_check_md5sum__remote {
+ my ($urpm, $medium, $retrieved_md5sum, $callback, $quiet) = @_;
+
+ get_hdlist_or_synthesis__remote($urpm, $medium, $callback, $quiet) or return;
+
+ #- check downloaded file has right signature.
+ if ($retrieved_md5sum) {
+ $urpm->{log}(N("computing md5sum of retrieved source hdlist (or synthesis)"));
+ urpm::md5sum::compute(cachedir_with_hdlist($urpm, $medium)) eq $retrieved_md5sum or
+ $urpm->{error}(N("...retrieving failed: md5sum mismatch")), return;
+ }
+ 1;
+}
sub _read_rpms_from_dir {
my ($urpm, $medium, $need_second_pass, $clean_cache) = @_;
@@ -1388,7 +1415,14 @@ sub _update_medium__parse_if_unmodified__remote {
#- it is already defined (and valid).
$urpm->{log}(N("retrieving source hdlist (or synthesis) of \"%s\"...", $medium->{name}));
$options->{callback} and $options->{callback}('retrieve', $medium->{name});
+ my $error = sub {
+ my ($msg) = @_;
+ $urpm->{error}($msg);
+ unlink cachedir_with_hdlist($urpm, $medium);
+ $options->{callback} and $options->{callback}('failed', $medium->{name});
+ };
if ($options->{probe_with} && !$medium->{with_hdlist}) {
+ my $err;
foreach my $with_hdlist (_probe_with_try_list($options->{probe_with})) {
my $f = "$urpm->{cachedir}/partial/" . basename($with_hdlist);
$options->{force} and unlink $f;
@@ -1398,8 +1432,15 @@ sub _update_medium__parse_if_unmodified__remote {
$medium->{with_hdlist} = $with_hdlist;
$urpm->{log}(N("found probed hdlist (or synthesis) as %s", $medium->{with_hdlist}));
last; #- found a suitable with_hdlist in the list above.
+ } else {
+ chomp($err = $@);
}
}
+ if (!$medium->{with_hdlist}) {
+ $error->(N("no hdlist file found for medium \"%s\"", $medium->{name}));
+ $urpm->{error}(N("...retrieving failed: %s", $err));
+ return;
+ }
} else {
if ($options->{force}) {
unlink cachedir_with_hdlist($urpm, $medium);
@@ -1410,40 +1451,24 @@ sub _update_medium__parse_if_unmodified__remote {
copy_and_own(
statedir_hdlist_or_synthesis($urpm, $medium),
cachedir_with_hdlist($urpm, $medium),
- ) or $urpm->{error}(N("...copying failed")), return;
+ ) or $error->(N("...copying failed")), return;
}
}
- if (urpm::download::sync($urpm, $medium, [ _url_with_hdlist($medium) ],
- quiet => $options->{quiet}, callback => $options->{callback})) {
- $urpm->{log}(N("...retrieving done"));
- } else {
- $urpm->{error}(N("...retrieving failed: %s", $@));
- unlink cachedir_with_hdlist($urpm, $medium);
- }
- }
+ if (get_hdlist_or_synthesis_and_check_md5sum__remote($urpm, $medium, $retrieved_md5sum, $options->{callback}, $options->{quiet})) {
+ $options->{callback} and $options->{callback}('done', $medium->{name});
- #- check downloaded file has right signature.
- if (file_size(cachedir_with_hdlist($urpm, $medium)) >= 20 && $retrieved_md5sum) {
- $urpm->{log}(N("computing md5sum of retrieved source hdlist (or synthesis)"));
- unless (urpm::md5sum::compute(cachedir_with_hdlist($urpm, $medium)) eq $retrieved_md5sum) {
- $urpm->{error}(N("...retrieving failed: md5sum mismatch"));
- unlink cachedir_with_hdlist($urpm, $medium);
- }
- }
+ $medium->{md5sum} = $retrieved_md5sum if $retrieved_md5sum;
- if (file_size(cachedir_with_hdlist($urpm, $medium)) >= 20) {
- $options->{callback} and $options->{callback}('done', $medium->{name});
-
- unless ($options->{force}) {
- _read_existing_synthesis_and_hdlist_if_same_time_and_msize($urpm, $medium)
- and return 'unmodified';
+ if (!$options->{force}) {
+ _read_existing_synthesis_and_hdlist_if_same_time_and_msize($urpm, $medium)
+ and return 'unmodified';
+ }
+ } else {
+ $error->(N("unable to access hdlist file of \"%s\", medium ignored", $medium->{name}));
+ $medium->{ignore} = 1;
+ return;
}
- } else {
- $options->{callback} and $options->{callback}('failed', $medium->{name});
- $urpm->{error}(N("retrieval of source hdlist (or synthesis) failed"));
- return;
}
- $urpm->{md5sum} = $retrieved_md5sum if $retrieved_md5sum;
1;
}