diff options
Diffstat (limited to 'urpm.pm')
-rw-r--r-- | urpm.pm | 35 |
1 files changed, 11 insertions, 24 deletions
@@ -274,7 +274,6 @@ sub read_config { #- probe medium to be used, take old medium into account too. sub probe_medium { my ($urpm, $medium, %options) = @_; - local $_; if (name2medium($urpm, $medium->{name})) { $urpm->{error}(N("trying to override existing medium \"%s\", skipping", $medium->{name})); @@ -316,8 +315,8 @@ sub probe_medium { unless ($medium->{url}) { my %probe; if (-r statedir_list($urpm, $medium)) { - my $listfile = $urpm->open_safe("<", statedir_list($urpm, $medium)); - if ($listfile) { + if (my $listfile = $urpm->open_safe("<", statedir_list($urpm, $medium))) { + local $_; while (<$listfile>) { #- /./ is end of url marker in list file (typically generated by a #- find . -name "*.rpm" > list @@ -325,7 +324,6 @@ sub probe_medium { m|^(.*)/\./| and $probe{$1} = undef; m|^(.*)/[^/]*$| and $probe{$1} = undef; } - close $listfile; } } foreach (sort { length($a) <=> length($b) } keys %probe) { @@ -1152,8 +1150,7 @@ sub generate_media_names { foreach (@{$urpm->{media}}) { unlink statedir_names($urpm, $_); if (is_valid_medium($_)) { - my $fh = $urpm->open_safe(">", statedir_names($urpm, $_)); - if ($fh) { + if (my $fh = $urpm->open_safe(">", statedir_names($urpm, $_))) { foreach ($_->{start} .. $_->{end}) { if (defined $urpm->{depslist}[$_]) { print $fh $urpm->{depslist}[$_]->name . "\n"; @@ -1161,7 +1158,6 @@ sub generate_media_names { $urpm->{error}(N("Error generating names file: dependency %d not found", $_)); } } - close $fh; } else { $urpm->{error}(N("Error generating names file: Can't write to file (%s)", $!)); } @@ -1765,14 +1761,13 @@ sub _update_medium_first_pass { @unresolved_before == @unresolved_after or $$second_pass = 1; if ($medium->{hdlist} ne 'list' && -s "$urpm->{cachedir}/partial/list") { - if (open my $fh, "$urpm->{cachedir}/partial/list") { + if (open(my $fh, '<', "$urpm->{cachedir}/partial/list")) { local $_; while (<$fh>) { m|/([^/]*\.rpm)$| or next; $list{$1} and $urpm->{error}(N("file [%s] already used in the same medium \"%s\"", $1, $medium->{name})), next; $list{$1} = "$medium->{url}/$_"; } - close $fh; } } else { #- if url is clear and no relative list file has been downloaded, @@ -1793,11 +1788,9 @@ sub _update_medium_first_pass { #- make sure group and other do not have any access to this file, used to hide passwords. if ($medium->{list}) { my $mask = umask 077; - open my $listfh, ">", cachedir_list($urpm, $medium) - or $error = 1, $urpm->{error}(N("unable to write list file of \"%s\"", $medium->{name})); + my $listfh = $urpm->open_safe('>', cachedir_list($urpm, $medium)) or $error = 1; umask $mask; print $listfh values %list; - close $listfh; } #- check if at least something has been written into list file. @@ -2406,13 +2399,12 @@ sub create_transaction { sub get_packages_list { my ($file, $o_extra) = @_; my $val = []; - open my $f, $file or return []; + open(my $f, '<', $file) or return []; foreach (<$f>, split /,/, $o_extra || '') { chomp; s/#.*$//; s/^\s*//; s/\s*$//; next if $_ eq ''; push @$val, $_; } - close $f; $val; } @@ -2490,8 +2482,7 @@ sub get_source_packages { -s $listfile or $listfile = "$dir/list"; } if ($listfile && -r $listfile) { - my $fh = $urpm->open_safe('<', $listfile); - if ($fh) { + if (my $fh = $urpm->open_safe('<', $listfile)) { local $_; while (<$fh>) { chomp; @@ -2515,7 +2506,6 @@ sub get_source_packages { last; } } - close $fh; } } elsif ($listfile && -e $listfile) { # list file exists but isn't readable @@ -2611,10 +2601,8 @@ sub _lock { #- lock urpmi database, but keep lock to wait for an urpmi.update to finish. } else { #- create the .LOCK file if needed (and if possible) - unless (-e $file) { - open(my $f, ">", $file); - close $f; - } + -e $file or open(my $_f, ">", $file); + #- lock urpmi database, if the LOCK file doesn't exists no share lock. } my ($sense, $mode) = $b_exclusive ? ('>', $LOCK_EX) : ('<', $LOCK_SH); @@ -3050,10 +3038,9 @@ sub install { if ($::verbose >= 0 && keys %readmes) { foreach (keys %readmes) { print "-" x 70, "\n", N("More information on package %s", $readmes{$_}), "\n"; - my $fh; open $fh, '<', $_ and do { + if (open(my $fh, '<', $_)) { print while <$fh>; - close $fh; - }; + } print "-" x 70, "\n"; } } |