From 52734f88a237a83a09e9fda07ddd14606a71e062 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Sun, 24 Feb 2008 10:58:31 +0000 Subject: display a "bad rpms" message instead of "files are missing" when the downloaded rpm is bad. this adds a new callback for rpmdrake: "bad_rpms" this modifies the API of urpm::get_pkgs::download_packages_of_distant_media ($error_sources is now { url => reason } instead of { id => url }) --- urpm/get_pkgs.pm | 27 +++++++++++++++++---------- urpm/main_loop.pm | 12 +++++++++--- 2 files changed, 26 insertions(+), 13 deletions(-) (limited to 'urpm') diff --git a/urpm/get_pkgs.pm b/urpm/get_pkgs.pm index b6a792dc..4bda4e99 100644 --- a/urpm/get_pkgs.pm +++ b/urpm/get_pkgs.pm @@ -110,6 +110,8 @@ sub selected2list { sub download_packages_of_distant_media { my ($urpm, $list, $sources, $error_sources, %options) = @_; + my %errors; + #- get back all ftp and http accessible rpm files into the local cache foreach my $n (0..$#$list) { my %distant_sources; @@ -126,7 +128,7 @@ sub download_packages_of_distant_media { if (-r $local_file) { $sources->{$i} = $local_file; } else { - $error_sources->{$i} = $local_file; + $errors{$i} = [ $local_file, 'missing' ]; } } elsif ($url =~ m!^([^:]*):/(.*/([^/]*\.rpm))\Z!) { $distant_sources{$i} = "$1:/$2"; #- will download now @@ -165,22 +167,27 @@ sub download_packages_of_distant_media { #- present the error to the user. foreach my $i (keys %distant_sources) { my ($filename) = $distant_sources{$i} =~ m|/([^/]*\.rpm)$|; - if ($filename && -s "$partial_dir/$filename" && - URPM::verify_rpm("$partial_dir/$filename", nosignatures => 1)) - { - #- it seems the the file has been downloaded correctly and has been checked to be valid. - unlink "$rpms_dir/$filename"; - urpm::sys::move_or_die($urpm, "$partial_dir/$filename", "$rpms_dir/$filename"); - $sources->{$i} = "$rpms_dir/$filename"; + if ($filename && -s "$partial_dir/$filename") { + if (URPM::verify_rpm("$partial_dir/$filename", nosignatures => 1)) { + #- it seems the the file has been downloaded correctly and has been checked to be valid. + unlink "$rpms_dir/$filename"; + urpm::sys::move_or_die($urpm, "$partial_dir/$filename", "$rpms_dir/$filename"); + $sources->{$i} = "$rpms_dir/$filename"; + } else { + unlink "$partial_dir/$filename"; + $errors{$i} = [ $distant_sources{$i}, 'bad' ]; + } } else { - $error_sources->{$i} = $distant_sources{$i}; + $errors{$i} = [ $distant_sources{$i}, 'missing' ]; } } } } #- clean failed download which have succeeded. - delete @$error_sources{keys %$sources}; + delete @$errors{keys %$sources}; + + %$error_sources = map { @$_ } values %errors; 1; } diff --git a/urpm/main_loop.pm b/urpm/main_loop.pm index 6491dab0..0b93be47 100644 --- a/urpm/main_loop.pm +++ b/urpm/main_loop.pm @@ -252,13 +252,19 @@ $callbacks->{completed} and $callbacks->{completed}->(); #- keep a track of error code. my $exit_code = 0; -if (values %error_sources) { - $callbacks->{missing_files_summary} and $callbacks->{missing_files_summary}->(\%error_sources); +if (my @missing = grep { $error_sources{$_} eq 'missing' } keys %error_sources) { + $callbacks->{missing_files_summary} and $callbacks->{missing_files_summary}->({ map { $_ => $_ } @missing }); #- Warning : the following message is parsed in urpm::parallel_* print N("Installation failed, some files are missing:\n%s\nYou may want to update your urpmi database", - join "\n", map { s|([^:]*://[^/:\@]*:)[^/:\@]*(\@.*)|$1xxxx$2|; " $_" } values %error_sources), "\n"; + join "\n", map { " " . urpm::download::hide_password($_) } @missing), "\n"; $exit_code = 10; } +if (my @bad = grep { $error_sources{$_} eq 'bad' } keys %error_sources) { + $callbacks->{bad_rpms} and $callbacks->{bad_rpms}->(@bad); + print N("Installation failed, bad rpms:\n%s", + join "\n", map { " " . urpm::download::hide_password($_) } @bad), "\n"; + $exit_code = 11; +} if ($nok) { $callbacks->{trans_error_summary} and $callbacks->{trans_error_summary}->($nok, \@errors); $nok > 1 and print P("%d installation transaction failed", -- cgit v1.2.1