Subject: | doesn't preserve symbolic links |
I think that dircopy in this module should copy symbolic links
as symbolic links instead of copying the target of the
symbolic link.
If you're just calling fcopy, then the functionality is
very specific and it's clear what should happen. The
symbolic link's target should be copied to the destination.
However, when you use dircopy, it's not obvious what
the module will do with symbolic links. I suggest that
the common expectation is that symbolic links get
preserved, but dircopy doesn't preserve them.
for exmaple, on a Unix shell:
cd ~/testdir
ln -s bunchOfData tinylink
Here, "tinylink" is a symbolic link of "bunchOfData"
and its size reflects that.
Then, in perl, do dircopy("testdir","copytestdir")
and you'll find that "copytestdir/tinylink" is a file with the
same contents as "bunchOfData"
I have supplied a patch which, I think, appropriately
implements the preservation of symbolic links in dircopy.
This is perl, v5.8.0 built for i386-linux-thread-multi
(with 1 registered patch, see perl -V for more detail)
% uname -a
Linux mycomputer 2.4.20-30.8.legacy #1 Fri Feb 20 17:47:48 PST 2004 i686 i686 i386 GNU/Linux
*** orig/File/Copy/Recursive.pm Mon Jan 24 17:10:49 2005
--- File/Copy/Recursive.pm Thu Apr 14 18:01:55 2005
***************
*** 33,40 ****
--- 33,47 ----
my $level = 0;
my $filen = 0;
my $dirn = 0;
+ # check if this system can symlink
+ my $can_symlink = eval { symlink("",""); 1 };
+ unless ($can_symlink) {
+ warn "this system can't make symbolic links, files will be copied",
+ " instead of linked.\n";
+ }
+
my $recurs; #must be my()ed before sub {} since it calls itself
$recurs = sub {
my ($str,$end,$buf) = @_;
$filen++ if $end eq $baseend;
***************
*** 58,65 ****
--- 65,75 ----
$recurs->($org,$new,$buf) if defined $buf;
$recurs->($org,$new) if !defined $buf;
$filen++;
$dirn++;
+ } elsif ((-l $org) and $can_symlink) {
+ symlink( readlink($org), $new );
+ $filen++;
} else {
copy($org,$new,$buf) or return if defined $buf;
copy($org,$new) or return if !defined $buf;
chmod scalar((stat($org))[2]), $new if $KeepMode;