summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@mandriva.org>2004-07-26 09:54:00 +0000
committerRafael Garcia-Suarez <rgarciasuarez@mandriva.org>2004-07-26 09:54:00 +0000
commitd42a6414b2e7faa6e5601b50093e60bc6762f63e (patch)
treec8e05e06590ba9c88649fe2f7d176a190ed2e07b
parent3012a07ac593661d173c9239f52a20a19e598657 (diff)
downloadurpmi-d42a6414b2e7faa6e5601b50093e60bc6762f63e.tar
urpmi-d42a6414b2e7faa6e5601b50093e60bc6762f63e.tar.gz
urpmi-d42a6414b2e7faa6e5601b50093e60bc6762f63e.tar.bz2
urpmi-d42a6414b2e7faa6e5601b50093e60bc6762f63e.tar.xz
urpmi-d42a6414b2e7faa6e5601b50093e60bc6762f63e.zip
Modernize.
-rw-r--r--urpm.pm96
1 files changed, 45 insertions, 51 deletions
diff --git a/urpm.pm b/urpm.pm
index 6d212a02..3814e39a 100644
--- a/urpm.pm
+++ b/urpm.pm
@@ -270,16 +270,15 @@ sub probe_medium {
unless ($medium->{url}) {
my %probe;
if (-r "$urpm->{statedir}/$medium->{list}") {
- local *L;
- open L, "$urpm->{statedir}/$medium->{list}";
- while (<L>) {
+ open my $listfile, "$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;
}
- close L;
+ close $listfile;
}
foreach (sort { length($a) <=> length($b) } keys %probe) {
if ($medium->{url}) {
@@ -392,26 +391,25 @@ sub configure {
my ($parallel_options, $parallel_handler);
#- handle parallel configuration, examine all module available that
#- will handle the parallel mode (configuration is /etc/urpmi/parallel.cfg).
- local ($_, *PARALLEL);
- open PARALLEL, "/etc/urpmi/parallel.cfg";
- while (<PARALLEL>) {
+ local $_;
+ open my $parallel, "/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;
}
- close PARALLEL;
+ close $parallel;
#- if a configuration options has been found, use it else fatal error.
if ($parallel_options) {
foreach my $dir (grep { -d $_ } map { "$_/urpm" } @INC) {
- local *DIR;
- opendir DIR, $dir;
- while ($_ = readdir DIR) {
+ opendir my $dh, $dir or die $!;
+ while ($_ = readdir $dh) {
-f "$dir/$_" or next;
$urpm->{log}->(N("examining parallel handler in file [%s]", "$dir/$_"));
eval { require "$dir/$_"; $parallel_handler = $urpm->handle_parallel_options($parallel_options) };
$parallel_handler and last;
}
- closedir DIR;
+ closedir $dh;
$parallel_handler and last;
}
}
@@ -573,18 +571,17 @@ sub configure {
my $sig_handler = sub { undef $db; exit 3 };
local $SIG{INT} = $sig_handler;
local $SIG{QUIT} = $sig_handler;
- local *RPMDB;
$db or $urpm->{fatal}(9, N("unable to open rpmdb"));
- open RPMDB, "| " . ($ENV{LD_LOADER} || '') . " gzip -9 >'$options{bug}/rpmdb.cz'";
+ open my $rpmdb, "| " . ($ENV{LD_LOADER} || '') . " gzip -9 >'$options{bug}/rpmdb.cz'";
$db->traverse(sub {
my ($p) = @_;
#- this is not right but may be enough.
my $files = join '@', grep { exists($urpm->{provides}{$_}) } $p->files;
$p->pack_header;
- $p->build_info(fileno *RPMDB, $files);
+ $p->build_info(fileno $rpmdb, $files);
});
- close RPMDB;
+ close $rpmdb;
}
}
@@ -719,10 +716,9 @@ sub add_distrib_media {
#- at this point, we have found an hdlists file, so parse it
#- and create all necessary media according to it.
- local *HDLISTS;
- if (open HDLISTS, $hdlists_file) {
+ if (open my $hdlistsfh, $hdlists_file) {
my $medium = 1;
- foreach (<HDLISTS>) {
+ foreach (<$hdlistsfh>) {
chomp;
s/\s*#.*$//;
/^\s*$/ and next;
@@ -736,7 +732,7 @@ sub add_distrib_media {
++$medium;
}
- close HDLISTS;
+ close $hdlistsfh;
} else {
$urpm->{error}(N("unable to access first installation medium (no hdlists file found)")), return;
}
@@ -1112,15 +1108,15 @@ this could happen if you mounted manually the directory when creating the medium
}
if ($medium->{md5sum}) {
$urpm->{log}(N("examining MD5SUM file"));
- local (*F, $_);
- open F, reduce_pathname("$with_hdlist_dir/../MD5SUM");
- while (<F>) {
+ local $_;
+ open my $fh, reduce_pathname("$with_hdlist_dir/../MD5SUM");
+ while (<$fh>) {
my ($md5sum, $file) = m|(\S+)\s+(?:\./)?(\S+)| or next;
#- keep md5sum got here to check download was ok ! so even if md5sum is not defined, we need
#- to compute it, keep it in mind ;)
$file eq $basename and $retrieved_md5sum = $md5sum;
}
- close F;
+ close $fh;
#- If an existing hdlist or synthesis file has the same md5sum, we assume
#- the files are the same.
#- If the local md5sum is the same as the distant md5sum, this means
@@ -1385,15 +1381,15 @@ this could happen if you mounted manually the directory when creating the medium
}
if ($medium->{md5sum}) {
$urpm->{log}(N("examining MD5SUM file"));
- local (*F, $_);
- open F, "$urpm->{cachedir}/partial/MD5SUM";
- while (<F>) {
+ local $_;
+ open my $fh, "$urpm->{cachedir}/partial/MD5SUM";
+ while (<$fh>) {
my ($md5sum, $file) = m|(\S+)\s+(?:\./)?(\S+)| or next;
#- keep md5sum got here to check download was ok ! so even if md5sum is not defined, we need
#- to compute it, keep it in mind ;)
$file eq $basename and $retrieved_md5sum = $md5sum;
}
- close F;
+ close $fh;
#- if an existing hdlist or synthesis file has the same md5sum, we assume the
#- file are the same.
#- if local md5sum is the same as distant md5sum, this means there is no need to
@@ -1680,14 +1676,14 @@ this could happen if you mounted manually the directory when creating the medium
@unresolved_before == @unresolved_after or $second_pass = 1;
if ($medium->{hdlist} ne 'list' && -s "$urpm->{cachedir}/partial/list") {
- local (*F, $_);
- open F, "$urpm->{cachedir}/partial/list";
- while (<F>) {
+ local $_;
+ open my $fh, "$urpm->{cachedir}/partial/list";
+ 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 F;
+ close $fh;
} else {
#- if url is clear and no relative list file has been downloaded,
#- there is no need for a list file.
@@ -1704,14 +1700,13 @@ this could happen if you mounted manually the directory when creating the medium
unless ($error) {
if (%list) {
#- write list file.
- local *LIST;
#- make sure group and other do not have any access to this file, used to hide passwords.
my $mask = umask 077;
- open LIST, ">$urpm->{cachedir}/partial/$medium->{list}"
+ open my $listfh, ">$urpm->{cachedir}/partial/$medium->{list}"
or $error = 1, $urpm->{error}(N("unable to write list file of \"%s\"", $medium->{name}));
umask $mask;
- print LIST values %list;
- close LIST;
+ print $listfh values %list;
+ close $listfh;
#- check if at least something has been written into list file.
if (-s "$urpm->{cachedir}/partial/$medium->{list}") {
@@ -1867,13 +1862,13 @@ this could happen if you mounted manually the directory when creating the medium
#- useful according to the depslist.
if ($urpm->{modified}) {
if ($options{noclean}) {
- local (*D, $_);
+ local $_;
my %headers;
- opendir D, "$urpm->{cachedir}/headers";
- while (defined($_ = readdir D)) {
+ opendir my $dh, "$urpm->{cachedir}/headers";
+ while (defined($_ = readdir $dh)) {
m|^([^/]*-[^-]*-[^-]*\.[^\.]*)(?::\S*)?$| and $headers{$1} = $_;
}
- closedir D;
+ closedir $dh;
$urpm->{log}(N("found %d headers in cache", scalar(keys %headers)));
foreach (@{$urpm->{depslist}}) {
delete $headers{$_->fullname};
@@ -1893,12 +1888,11 @@ this could happen if you mounted manually the directory when creating the medium
foreach (@{$urpm->{media}}) {
unlink "$urpm->{statedir}/names.$_->{name}";
if (defined $_->{start} && defined $_->{end}) {
- local *F;
- open F, ">$urpm->{statedir}/names.$_->{name}";
+ open my $fh, ">$urpm->{statedir}/names.$_->{name}";
foreach ($_->{start} .. $_->{end}) {
- print F $urpm->{depslist}[$_]->name."\n";
+ print $fh $urpm->{depslist}[$_]->name."\n";
}
- close F;
+ close $fh;
}
}
@@ -2271,7 +2265,7 @@ sub get_packages_list {
sub get_source_packages {
my ($urpm, $packages, %options) = @_;
my ($id, $error, @list_error, %protected_files, %local_sources, @list, %fullname2id, %file2fullnames, %examined);
- local (*D, *F, $_);
+ local $_;
#- build association hash to retrieve id and examine all list files.
foreach (keys %$packages) {
@@ -2290,8 +2284,8 @@ sub get_source_packages {
}
#- examine the local repository, which is trusted (no gpg or pgp signature check but md5 is now done).
- opendir D, "$urpm->{cachedir}/rpms";
- while (defined($_ = readdir D)) {
+ opendir my $dh, "$urpm->{cachedir}/rpms";
+ while (defined($_ = readdir $dh)) {
if (my ($filename) = m|^([^/]*\.rpm)$|) {
my $filepath = "$urpm->{cachedir}/rpms/$filename";
if (!$options{clean_all} && -s $filepath) {
@@ -2314,7 +2308,7 @@ sub get_source_packages {
}
} #- no error on unknown filename located in cache (because .listing) inherited from old urpmi
}
- closedir D;
+ closedir $dh;
#- clean download directory, do it here even if this is not the best moment.
if ($options{clean_all}) {
@@ -2336,8 +2330,8 @@ sub get_source_packages {
-s $file or $file = "$dir/list";
}
if ($file && -r $file) {
- open F, $file;
- while (<F>) {
+ open my $fh, $file or die $!;
+ 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);
@@ -2355,7 +2349,7 @@ sub get_source_packages {
last;
}
}
- close F;
+ 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