summaryrefslogtreecommitdiffstats
path: root/urpm/util.pm
diff options
context:
space:
mode:
Diffstat (limited to 'urpm/util.pm')
-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 }