summaryrefslogtreecommitdiffstats
path: root/perl-install/common.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/common.pm')
-rw-r--r--perl-install/common.pm40
1 files changed, 40 insertions, 0 deletions
diff --git a/perl-install/common.pm b/perl-install/common.pm
index 170ad831d..93004c37f 100644
--- a/perl-install/common.pm
+++ b/perl-install/common.pm
@@ -308,4 +308,44 @@ sub unpack_with_refs {
@r;
}
+
+sub my_cp_with_option {
+ my $option = shift @_;
+ my $keep_special = $option =~ /a/;
+
+ my $dest = pop @_;
+
+ @_ or return;
+ @_ == 1 || -d $dest or die "cp: copying multiple files, but last argument ($dest) is not a directory\n";
+
+ foreach my $src (@_) {
+ my $dest = $dest;
+ -d $dest and $dest .= '/' . basename($src);
+
+ unlink $dest;
+
+ if (-l $src && $keep_special) {
+ unless (symlink(readlink($src) || die("readlink failed: $!"), $dest)) {
+ warn "symlink: can't create symlink $dest: $!\n";
+ }
+ } elsif (-d $src) {
+ -d $dest or mkdir $dest, (stat($src))[2] or die "mkdir: can't create directory $dest: $!\n";
+ my_cp_af(glob_($src), $dest);
+ } elsif ((-b $src || -c $src) && $keep_special) {
+ my @stat = stat($src);
+ require MDK::Common::System;
+ MDK::Common::System::syscall_('mknod', $dest, $stat[2], $stat[6]) or die "mknod failed (dev $dest): $!";
+ } else {
+ open(my $F, $src) or die "can't open $src for reading: $!\n";
+ open(my $G, "> $dest") or die "can't cp to file $dest: $!\n";
+ local $_; while (<$F>) { print $G $_ }
+ chmod((stat($src))[2], $dest);
+ }
+ }
+ 1;
+}
+
+sub my_cp_f { my_cp_with_option('f', @_) }
+sub my_cp_af { my_cp_with_option('af', @_) }
+
1;