From ba6f31845b6ac979f5ecaf4ed465bb8a8c6ce77a Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Wed, 15 Nov 2006 15:24:12 +0000 Subject: create copy_and_own, and use it --- urpm/util.pm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'urpm/util.pm') diff --git a/urpm/util.pm b/urpm/util.pm index ed1f885d..b12c49a0 100644 --- a/urpm/util.pm +++ b/urpm/util.pm @@ -9,6 +9,8 @@ our @EXPORT = qw(quotespace unquotespace remove_internal_name reduce_pathname offset_pathname md5sum untaint + copy_and_own + same_size_and_mtime difference2 member file_size cat_ dirname basename ); @@ -104,6 +106,10 @@ sub copy { my ($file, $dest) = @_; !system("/bin/cp", "-p", "-L", "-R", $file, $dest); } +sub copy_and_own { + my ($file, $dest_file) = @_; + copy($file, $dest_file) && chown(0, 0, $dest_file) == 1; +} sub move { my ($file, $dest) = @_; @@ -116,6 +122,14 @@ sub file_size { -s $file || 0; } +sub same_size_and_mtime { + my ($f1, $f2) = @_; + + my @sstat = stat $f1; + my @lstat = stat $f2; + $sstat[7] == $lstat[7] && $sstat[9] == $lstat[9]; +} + 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 } -- cgit v1.2.1