summaryrefslogtreecommitdiffstats
path: root/urpm.pm
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2006-11-15 17:22:50 +0000
committerPascal Rigaux <pixel@mandriva.com>2006-11-15 17:22:50 +0000
commit2904420468502937053df7b40a3ad1c2b36abb98 (patch)
tree6ae109a9f0b9d0c25f247b5594dfd6e3627951c9 /urpm.pm
parent005aae665ff408fe42d4b8bbfc744866d20007b0 (diff)
downloadurpmi-2904420468502937053df7b40a3ad1c2b36abb98.tar
urpmi-2904420468502937053df7b40a3ad1c2b36abb98.tar.gz
urpmi-2904420468502937053df7b40a3ad1c2b36abb98.tar.bz2
urpmi-2904420468502937053df7b40a3ad1c2b36abb98.tar.xz
urpmi-2904420468502937053df7b40a3ad1c2b36abb98.zip
remove unneeded close(), simplify
Diffstat (limited to 'urpm.pm')
-rw-r--r--urpm.pm35
1 files changed, 11 insertions, 24 deletions
diff --git a/urpm.pm b/urpm.pm
index 9441d59a..d0ce20f0 100644
--- a/urpm.pm
+++ b/urpm.pm
@@ -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";
}
}