summaryrefslogtreecommitdiffstats
path: root/urpm
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2006-11-09 14:56:39 +0000
committerPascal Rigaux <pixel@mandriva.com>2006-11-09 14:56:39 +0000
commit15a55bd9f257454bee6d63c230acae750ae379de (patch)
treed23a29de14697bfe6ec5dc52dfff0cc6da911ba7 /urpm
parent64495e8b0d16d2d3a091898c35d4ac86d570b049 (diff)
downloadurpmi-15a55bd9f257454bee6d63c230acae750ae379de.tar
urpmi-15a55bd9f257454bee6d63c230acae750ae379de.tar.gz
urpmi-15a55bd9f257454bee6d63c230acae750ae379de.tar.bz2
urpmi-15a55bd9f257454bee6d63c230acae750ae379de.tar.xz
urpmi-15a55bd9f257454bee6d63c230acae750ae379de.zip
move basename() to urpm::util
Diffstat (limited to 'urpm')
-rw-r--r--urpm/download.pm2
-rw-r--r--urpm/parallel_ka_run.pm17
-rw-r--r--urpm/parallel_ssh.pm18
-rw-r--r--urpm/util.pm18
4 files changed, 32 insertions, 23 deletions
diff --git a/urpm/download.pm b/urpm/download.pm
index 3b94168b..7655c141 100644
--- a/urpm/download.pm
+++ b/urpm/download.pm
@@ -17,8 +17,6 @@ my $proxy_config;
#- Timeout for curl connection and wget operations
our $CONNECT_TIMEOUT = 60; #- (in seconds)
-sub basename { local $_ = shift; s|/*\s*$||; s|.*/||; $_ }
-
sub import () {
my $c = caller;
no strict 'refs';
diff --git a/urpm/parallel_ka_run.pm b/urpm/parallel_ka_run.pm
index 868fd149..6d743cc9 100644
--- a/urpm/parallel_ka_run.pm
+++ b/urpm/parallel_ka_run.pm
@@ -14,11 +14,11 @@ our $rshp_command = $ENV{URPMI_RSHP_COMMAND};
if (!$mput_command) {
($mput_command) = grep { -x $_ } qw(/usr/bin/mput2 /usr/bin/mput);
}
-$mput_command = 'mput' unless $mput_command;
+$mput_command ||= 'mput';
if (!$rshp_command) {
($rshp_command) = grep { -x $_ } qw(/usr/bin/rshp2 /usr/bin/rshp);
}
-$rshp_command = 'rshp' unless $rshp_command;
+$rshp_command ||= 'rshp';
#- parallel copy
sub parallel_register_rpms {
@@ -30,7 +30,7 @@ sub parallel_register_rpms {
#- keep trace of direct files.
foreach (@files) {
- my $basename = (/^.*\/([^\/]*)$/ && $1) || $_;
+ my $basename = basename($_);
$parallel->{line} .= "'$urpm->{cachedir}/rpms/$basename' ";
}
}
@@ -90,8 +90,9 @@ sub parallel_find_remove {
close $fh or $urpm->{fatal}(1, urpm::N("rshp failed, maybe a node is unreacheable"));
#- check base, which has been delayed until there.
- $options{callback_base} and %base_to_remove and $options{callback_base}->($urpm, keys %base_to_remove)
- || return ();
+ if ($options{callback_base} && %base_to_remove) {
+ $options{callback_base}->($urpm, keys %base_to_remove) or return ();
+ }
#- build error list contains all the error returned by each node.
$urpm->{error_remove} = [];
@@ -119,7 +120,7 @@ sub parallel_resolve_dependencies {
#- first propagate the synthesis file to all machine.
$urpm->{ui_msg}("parallel_ka_run: $mput_command $parallel->{options} -- '$synthesis' '$synthesis'", urpm::N("Propagating synthesis to nodes..."));
- system "$mput_command $parallel->{options} -- '$synthesis' '$synthesis'";
+ system($mput_command, $parallel->{options}, '--', $synthesis, $synthesis);
$? == 0 || $? == 256 or $urpm->{fatal}(1, urpm::N("mput failed, maybe a node is unreacheable"));
$parallel->{synthesis} = $synthesis;
@@ -205,14 +206,14 @@ sub parallel_resolve_dependencies {
} while $cont;
#- keep trace of what has been chosen finally (if any).
- $parallel->{line} = "$line ".join(' ', keys %chosen);
+ $parallel->{line} = join(' ', $line, keys %chosen);
}
#- parallel install.
sub parallel_install {
my ($parallel, $urpm, undef, $install, $upgrade, %options) = @_;
- $urpm->{ui_msg}("parallel_ka_run: $mput_command $parallel->{options} -- ".join(' ', values %$install, values %$upgrade)." $urpm->{cachedir}/rpms/", urpm::N("Distributing files to nodes..."));
+ $urpm->{ui_msg}("parallel_ka_run: $mput_command $parallel->{options} -- " . join(' ', values %$install, values %$upgrade) . " $urpm->{cachedir}/rpms/", urpm::N("Distributing files to nodes..."));
system $mput_command, split(' ', $parallel->{options}), '--', values %$install, values %$upgrade, "$urpm->{cachedir}/rpms/";
$? == 0 || $? == 256 or $urpm->{fatal}(1, urpm::N("mput failed, maybe a node is unreacheable"));
diff --git a/urpm/parallel_ssh.pm b/urpm/parallel_ssh.pm
index 4e15e787..a838c78f 100644
--- a/urpm/parallel_ssh.pm
+++ b/urpm/parallel_ssh.pm
@@ -8,7 +8,7 @@ package urpm::parallel_ssh;
use strict;
use Time::HiRes qw(gettimeofday);
-(our $VERSION) = q$Revision$ =~ /(\d+)/;
+(our $VERSION) = q($Revision$) =~ /(\d+)/;
sub _localhost { $_[0] eq 'localhost' }
sub _nolock { &_localhost ? '--nolock ' : '' }
@@ -32,7 +32,7 @@ sub parallel_register_rpms {
#- keep trace of direct files.
foreach (@files) {
- my $basename = (/^.*\/([^\/]*)$/ && $1) || $_;
+ my $basename = basename($_);
$parallel->{line} .= "'$urpm->{cachedir}/rpms/$basename' ";
}
}
@@ -73,7 +73,7 @@ sub parallel_find_remove {
#- if other nodes have it.
@notfound{split /, /, $1} = ();
} elsif (/The following packages contain ([^:]*): (.*)/) {
- $options{callback_fuzzy} and $options{callback_fuzzy}->($urpm, $1, split " ", $2)
+ $options{callback_fuzzy} && $options{callback_fuzzy}->($urpm, $1, split(" ", $2))
or delete $state->{rejected}, last;
} elsif (/removing package (.*) will break your system/) {
$base_to_remove{$1} = undef;
@@ -95,8 +95,9 @@ sub parallel_find_remove {
}
#- check base, which has been delayed until there.
- $options{callback_base} and keys %base_to_remove
- and $options{callback_base}->($urpm, keys %base_to_remove) || return ();
+ if ($options{callback_base} && keys %base_to_remove) {
+ $options{callback_base}->($urpm, keys %base_to_remove) or return ();
+ }
#- build error list contains all the error returned by each node.
$urpm->{error_remove} = [];
@@ -110,7 +111,7 @@ sub parallel_find_remove {
#- if at least one node has the package, it should be seen as unknown...
delete @notfound{map { /^(.*)-[^-]*-[^-]*$/ } keys %{$state->{rejected}}};
if (keys %notfound) {
- $options{callback_notfound} and $options{callback_notfound}->($urpm, keys %notfound)
+ $options{callback_notfound} && $options{callback_notfound}->($urpm, keys %notfound)
or delete $state->{rejected};
}
@@ -162,7 +163,7 @@ sub parallel_resolve_dependencies {
} else {
my $pkg = $urpm->{depslist}[$_] or next;
$urpm->{source}{$pkg->id} and next; #- local packages have already been added.
- $line .= ' '.$pkg->fullname;
+ $line .= ' ' . $pkg->fullname;
}
}
@@ -267,7 +268,8 @@ sub parallel_install {
local $/ = \1;
my $log;
my $last_time;
- while ($_ = <$fh>) {
+ local $_;
+ while (<$fh>) {
print;
$log .= $_;
/\n/ and $log = '';
diff --git a/urpm/util.pm b/urpm/util.pm
index 75133c6c..f23c2076 100644
--- a/urpm/util.pm
+++ b/urpm/util.pm
@@ -9,7 +9,7 @@ our @EXPORT = qw(quotespace unquotespace
remove_internal_name
reduce_pathname offset_pathname
md5sum untaint
- difference2 member
+ difference2 member file_size cat_ basename
);
(our $VERSION) = q($Revision$) =~ /(\d+)/;
@@ -19,6 +19,8 @@ sub quotespace { my $x = $_[0] || ''; $x =~ s/(\s)/\\$1/g; $x }
sub unquotespace { my $x = $_[0] || ''; $x =~ s/\\(\s)/$1/g; $x }
sub remove_internal_name { my $x = $_[0] || ''; $x =~ s/\(\S+\)$/$1/g; $x }
+sub basename { local $_ = shift; s|/*\s*$||; s|.*/||; $_ }
+
#- reduce pathname by removing <something>/.. each time it appears (or . too).
sub reduce_pathname {
my ($url) = @_;
@@ -78,8 +80,7 @@ sub offset_pathname {
}
sub untaint {
- my @r;
- foreach (@_) { /(.*)/; push @r, $1 }
+ my @r = map { /(.*)/ } @_;
@r == 1 ? $r[0] : @r;
}
@@ -88,7 +89,7 @@ sub md5sum {
eval { require Digest::MD5 };
if ($@) {
#- Use an external command to avoid depending on perl
- return((split ' ', `/usr/bin/md5sum '$file'`)[0]);
+ return (split ' ', `/usr/bin/md5sum '$file'`)[0];
} else {
my $ctx = Digest::MD5->new;
open my $fh, $file or return '';
@@ -105,11 +106,18 @@ sub copy {
sub move {
my ($file, $dest) = @_;
- rename($file, $dest) or !system("/bin/mv", "-f", $file, $dest);
+ rename($file, $dest) || !system("/bin/mv", "-f", $file, $dest);
+}
+
+#- file_size is useful to write file_size(...) > 32 without having warnings if file doesn't exist
+sub file_size {
+ my ($file) = @_;
+ -s $file || 0;
}
sub difference2 { my %l; @l{@{$_[1]}} = (); grep { !exists $l{$_} } @{$_[0]} }
sub member { my $e = shift; foreach (@_) { $e eq $_ and return 1 } 0 }
+sub cat_ { my @l = map { my $F; open($F, '<', $_) ? <$F> : () } @_; wantarray() ? @l : join '', @l }
1;