summaryrefslogtreecommitdiffstats
path: root/urpm/util.pm
diff options
context:
space:
mode:
authorOlivier Blin <oblin@mandriva.com>2007-03-15 23:11:06 +0000
committerOlivier Blin <oblin@mandriva.com>2007-03-15 23:11:06 +0000
commit7194335ee9ccc6bc1d1a69d013eef55d20927037 (patch)
tree20006a13613a48398b91dc10abf2785264f80068 /urpm/util.pm
parent876f57a42dbff38925853104fe10ca08fe32e47f (diff)
downloadurpmi-7194335ee9ccc6bc1d1a69d013eef55d20927037.tar
urpmi-7194335ee9ccc6bc1d1a69d013eef55d20927037.tar.gz
urpmi-7194335ee9ccc6bc1d1a69d013eef55d20927037.tar.bz2
urpmi-7194335ee9ccc6bc1d1a69d013eef55d20927037.tar.xz
urpmi-7194335ee9ccc6bc1d1a69d013eef55d20927037.zip
move RFC/API/protocol doc in a dhcp-doc sub-package
Diffstat (limited to 'urpm/util.pm')
-rw-r--r--urpm/util.pm28
1 files changed, 16 insertions, 12 deletions
diff --git a/urpm/util.pm b/urpm/util.pm
index 520ce7f7..b12c49a0 100644
--- a/urpm/util.pm
+++ b/urpm/util.pm
@@ -8,10 +8,9 @@ our @ISA = 'Exporter';
our @EXPORT = qw(quotespace unquotespace
remove_internal_name
reduce_pathname offset_pathname
- untaint
+ md5sum untaint
copy_and_own
same_size_and_mtime
- partition uniq
difference2 member file_size cat_ dirname basename
);
@@ -88,6 +87,21 @@ sub untaint {
@r == 1 ? $r[0] : @r;
}
+sub md5sum {
+ my ($file) = @_;
+ eval { require Digest::MD5 };
+ if ($@) {
+ #- Use an external command to avoid depending on perl
+ return (split ' ', `/usr/bin/md5sum '$file'`)[0];
+ } else {
+ my $ctx = Digest::MD5->new;
+ open my $fh, $file or return '';
+ $ctx->addfile($fh);
+ close $fh;
+ return $ctx->hexdigest;
+ }
+}
+
sub copy {
my ($file, $dest) = @_;
!system("/bin/cp", "-p", "-L", "-R", $file, $dest);
@@ -116,16 +130,6 @@ sub same_size_and_mtime {
$sstat[7] == $lstat[7] && $sstat[9] == $lstat[9];
}
-sub partition(&@) {
- my $f = shift;
- my (@a, @b);
- foreach (@_) {
- $f->($_) ? push(@a, $_) : push(@b, $_);
- }
- \@a, \@b;
-}
-
-sub uniq { my %l; $l{$_} = 1 foreach @_; grep { delete $l{$_} } @_ }
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 }