summaryrefslogtreecommitdiffstats
path: root/urpm.pm
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@mandriva.org>2005-03-11 08:57:31 +0000
committerRafael Garcia-Suarez <rgarciasuarez@mandriva.org>2005-03-11 08:57:31 +0000
commit9b0b9383c8ee0b41b3d51d63cb4f8b1dde1f4751 (patch)
treee80169e5492bffc5d8c2ca4af3644c0cc0f0b87c /urpm.pm
parentae15cae5a187ac417c777fcb5ba2a0d2d281e1d5 (diff)
downloadurpmi-9b0b9383c8ee0b41b3d51d63cb4f8b1dde1f4751.tar
urpmi-9b0b9383c8ee0b41b3d51d63cb4f8b1dde1f4751.tar.gz
urpmi-9b0b9383c8ee0b41b3d51d63cb4f8b1dde1f4751.tar.bz2
urpmi-9b0b9383c8ee0b41b3d51d63cb4f8b1dde1f4751.tar.xz
urpmi-9b0b9383c8ee0b41b3d51d63cb4f8b1dde1f4751.zip
More error checking
Diffstat (limited to 'urpm.pm')
-rw-r--r--urpm.pm92
1 files changed, 51 insertions, 41 deletions
diff --git a/urpm.pm b/urpm.pm
index 2e23f1c4..8ecd2463 100644
--- a/urpm.pm
+++ b/urpm.pm
@@ -226,14 +226,16 @@ sub read_config {
#- read MD5 sums (usually not in urpmi.cfg but in a separate file)
my $md5sum = $urpm->open_safe("<", "$urpm->{statedir}/MD5SUM");
- while (<$md5sum>) {
- my ($md5sum, $file) = /(\S*)\s+(.*)/;
- foreach (@{$urpm->{media}}) {
- ($_->{synthesis} ? "synthesis." : "") . $_->{hdlist} eq $file
- and $_->{md5sum} = $md5sum, last;
+ if ($md5sum) {
+ while (<$md5sum>) {
+ my ($md5sum, $file) = /(\S*)\s+(.*)/;
+ foreach (@{$urpm->{media}}) {
+ ($_->{synthesis} ? "synthesis." : "") . $_->{hdlist} eq $file
+ and $_->{md5sum} = $md5sum, last;
+ }
}
+ close $md5sum;
}
- close $md5sum;
#- remember global options for write_config
$urpm->{global_config} = $config->{''};
@@ -287,14 +289,16 @@ sub probe_medium {
my %probe;
if (-r "$urpm->{statedir}/$medium->{list}") {
my $listfile = $urpm->open_safe("<", "$urpm->{statedir}/$medium->{list}");
- while (<$listfile>) {
- #- /./ is end of url marker in list file (typically generated by a
- #- find . -name "*.rpm" > list
- #- for exportable list file.
- m|^(.*)/\./| and $probe{$1} = undef;
- m|^(.*)/[^/]*$| and $probe{$1} = undef;
+ if ($listfile) {
+ while (<$listfile>) {
+ #- /./ is end of url marker in list file (typically generated by a
+ #- find . -name "*.rpm" > list
+ #- for exportable list file.
+ m|^(.*)/\./| and $probe{$1} = undef;
+ m|^(.*)/[^/]*$| and $probe{$1} = undef;
+ }
+ close $listfile;
}
- close $listfile;
}
foreach (sort { length($a) <=> length($b) } keys %probe) {
if ($medium->{url}) {
@@ -417,12 +421,14 @@ sub configure {
#- read parallel configuration
local $_;
my $parallel = $urpm->open_safe("<", "/etc/urpmi/parallel.cfg");
- while (<$parallel>) {
- chomp; s/#.*$//; s/^\s*//; s/\s*$//;
- /\s*([^:]*):(.*)/ or $urpm->{error}(N("unable to parse \"%s\" in file [%s]", $_, "/etc/urpmi/parallel.cfg")), next;
- $1 eq $options{parallel} and $parallel_options = ($parallel_options && "\n") . $2;
+ if ($parallel) {
+ while (<$parallel>) {
+ chomp; s/#.*$//; s/^\s*//; s/\s*$//;
+ /\s*([^:]*):(.*)/ or $urpm->{error}(N("unable to parse \"%s\" in file [%s]", $_, "/etc/urpmi/parallel.cfg")), next;
+ $1 eq $options{parallel} and $parallel_options = ($parallel_options && "\n") . $2;
+ }
+ close $parallel;
}
- close $parallel;
#- if a configuration option has been found, use it; else fatal error.
if ($parallel_options) {
foreach my $dir (grep { -d $_ } map { "$_/urpm" } @INC) {
@@ -2430,25 +2436,27 @@ sub get_source_packages {
}
if ($file && -r $file) {
my $fh = $urpm->open_safe('<', $file);
- while (<$fh>) {
- if (my ($filename) = m|/([^/]*\.rpm)$|) {
- if (keys(%{$file2fullnames{$filename} || {}}) > 1) {
- $urpm->{error}(N("there are multiple packages with the same rpm filename \"%s\"", $filename));
- next;
- } elsif (keys(%{$file2fullnames{$filename} || {}}) == 1) {
- my ($fullname) = keys(%{$file2fullnames{$filename} || {}});
- defined($id = $fullname2id{$fullname}) and $sources{$id} =
- $medium->{virtual} ? "$medium->{url}/$_" : $_;
- $list_examined{$fullname} = $examined{$fullname} = undef;
+ if ($fh) {
+ while (<$fh>) {
+ if (my ($filename) = m|/([^/]*\.rpm)$|) {
+ if (keys(%{$file2fullnames{$filename} || {}}) > 1) {
+ $urpm->{error}(N("there are multiple packages with the same rpm filename \"%s\"", $filename));
+ next;
+ } elsif (keys(%{$file2fullnames{$filename} || {}}) == 1) {
+ my ($fullname) = keys(%{$file2fullnames{$filename} || {}});
+ defined($id = $fullname2id{$fullname}) and $sources{$id} =
+ $medium->{virtual} ? "$medium->{url}/$_" : $_;
+ $list_examined{$fullname} = $examined{$fullname} = undef;
+ }
+ } else {
+ chomp;
+ $error = 1;
+ $urpm->{error}(N("unable to correctly parse [%s] on value \"%s\"", $file, $_));
+ last;
}
- } else {
- chomp;
- $error = 1;
- $urpm->{error}(N("unable to correctly parse [%s] on value \"%s\"", $file, $_));
- last;
}
+ close $fh;
}
- close $fh;
} elsif ($file && -e $file) {
# list file exists but isn't readable
# report error only if no result found, list files are only readable by root
@@ -2943,7 +2951,7 @@ sub install {
$options{callback_open} ||= sub {
my ($data, $type, $id) = @_;
$fh = $urpm->open_safe('<', $install->{$id} || $upgrade->{$id});
- return fileno $fh;
+ return defined $fh ? fileno $fh : undef;
};
$options{callback_close} ||= sub {
my ($urpm, undef, $pkgid) = @_;
@@ -2954,7 +2962,7 @@ sub install {
push @readmes, map { [ $_, $fullname ] } grep {
/\bREADME(\.$trtype)?\.urpmi$/;
} $pkg->files;
- close $fh;
+ close $fh if defined $fh;
};
if (scalar keys %$install || scalar keys %$upgrade) {
$options{callback_inst} ||= \&install_logger;
@@ -3287,12 +3295,14 @@ sub parse_md5sum {
my $retrieved_md5sum;
$urpm->{log}(N("examining MD5SUM file"));
my $fh = $urpm->open_safe('<', $path) or return undef;
- local $_;
- while (<$fh>) {
- my ($md5sum, $file) = m|(\S+)\s+(?:\./)?(\S+)| or next;
- $file eq $basename and $retrieved_md5sum = $md5sum;
+ if ($fh) {
+ local $_;
+ while (<$fh>) {
+ my ($md5sum, $file) = m|(\S+)\s+(?:\./)?(\S+)| or next;
+ $file eq $basename and $retrieved_md5sum = $md5sum;
+ }
+ close $fh;
}
- close $fh;
defined $retrieved_md5sum
or $urpm->{log}(N("warning: md5sum for %s unavailable in MD5SUM file", $basename));
return $retrieved_md5sum;