summaryrefslogtreecommitdiffstats
path: root/urpm
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2006-11-15 15:24:12 +0000
committerPascal Rigaux <pixel@mandriva.com>2006-11-15 15:24:12 +0000
commitba6f31845b6ac979f5ecaf4ed465bb8a8c6ce77a (patch)
tree38f5b04e7326452524c1f2d67ba4d4df38add640 /urpm
parent44b3028524dd01049132485fafa7d1d344546054 (diff)
downloadurpmi-ba6f31845b6ac979f5ecaf4ed465bb8a8c6ce77a.tar
urpmi-ba6f31845b6ac979f5ecaf4ed465bb8a8c6ce77a.tar.gz
urpmi-ba6f31845b6ac979f5ecaf4ed465bb8a8c6ce77a.tar.bz2
urpmi-ba6f31845b6ac979f5ecaf4ed465bb8a8c6ce77a.tar.xz
urpmi-ba6f31845b6ac979f5ecaf4ed465bb8a8c6ce77a.zip
create copy_and_own, and use it
Diffstat (limited to 'urpm')
-rw-r--r--urpm/util.pm14
1 files changed, 14 insertions, 0 deletions
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 }