Fix breakages that prevended -DPERL_POISON from compiling.
[p5sagit/p5-mst-13.2.git] / lib / File / Copy.pm
index fb256c0..57670e1 100644 (file)
@@ -10,7 +10,6 @@ package File::Copy;
 use 5.006;
 use strict;
 use warnings;
-use Carp;
 use File::Spec;
 use Config;
 our(@ISA, @EXPORT, @EXPORT_OK, $VERSION, $Too_Big, $Syscopy_is_copy);
@@ -24,7 +23,7 @@ sub mv;
 # package has not yet been updated to work with Perl 5.004, and so it
 # would be a Bad Thing for the CPAN module to grab it and replace this
 # module.  Therefore, we set this module's version higher than 2.0.
-$VERSION = '2.05';
+$VERSION = '2.08_01';
 
 require Exporter;
 @ISA = qw(Exporter);
@@ -33,6 +32,16 @@ require Exporter;
 
 $Too_Big = 1024 * 1024 * 2;
 
+sub croak {
+    require Carp;
+    goto &Carp::croak;
+}
+
+sub carp {
+    require Carp;
+    goto &Carp::carp;
+}
+
 my $macfiles;
 if ($^O eq 'MacOS') {
        $macfiles = eval { require Mac::MoreFiles };
@@ -74,17 +83,20 @@ sub copy {
                         : (ref(\$to) eq 'GLOB'));
 
     if ($from eq $to) { # works for references, too
-       croak("'$from' and '$to' are identical (not copied)");
+       carp("'$from' and '$to' are identical (not copied)");
+        # The "copy" was a success as the source and destination contain
+        # the same data.
+        return 1;
     }
 
-    if ($Config{d_symlink} && $Config{d_readlink} &&
-       !($^O eq 'Win32' || $^O eq 'os2' || $^O eq 'vms')) {
-       no warnings 'io'; # don't warn if -l on filehandle
-       if ((-e $from && -l $from) || (-e $to && -l $to)) {
-           my @fs = stat($from);
+    if ((($Config{d_symlink} && $Config{d_readlink}) || $Config{d_link}) &&
+       !($^O eq 'MSWin32' || $^O eq 'os2' || $^O eq 'vms')) {
+       my @fs = stat($from);
+       if (@fs) {
            my @ts = stat($to);
-           if (@fs && @ts && $fs[0] == $ts[0] && $fs[1] == $ts[1]) {
-               croak("'$from' and '$to' are identical (not copied)");
+           if (@ts && $fs[0] == $ts[0] && $fs[1] == $ts[1]) {
+               carp("'$from' and '$to' are identical (not copied)");
+                return 0;
            }
        }
     }
@@ -179,7 +191,10 @@ sub copy {
 }
 
 sub move {
+    croak("Usage: move(FROM, TO) ") unless @_ == 2;
+
     my($from,$to) = @_;
+
     my($fromsz,$tosz1,$tomt1,$tosz2,$tomt2,$sts,$ossts);
 
     if (-d $to && ! -d $from) {
@@ -202,7 +217,18 @@ sub move {
                 $tosz2 == $fromsz;                         # it's all there
 
     ($tosz1,$tomt1) = (stat($to))[7,9];  # just in case rename did something
-    return 1 if copy($from,$to) && unlink($from);
+
+    {
+        local $@;
+        eval {
+            local $SIG{__DIE__};
+            copy($from,$to) or die;
+            my($atime, $mtime) = (stat($from))[8,9];
+            utime($atime, $mtime, $to);
+            unlink($from)   or die;
+        };
+        return 1 unless $@;
+    }
     ($sts,$ossts) = ($! + 0, $^E + 0);
 
     ($tosz2,$tomt2) = ((stat($to))[7,9],0,0) if defined $tomt1;
@@ -275,11 +301,10 @@ File::Copy - Copy files or filehandles
        copy("Copy.pm",\*STDOUT);
        move("/dev1/fileA","/dev2/fileB");
 
-       use POSIX;
-       use File::Copy cp;
+       use File::Copy "cp";
 
        $n = FileHandle->new("/a/file","r");
-       cp($n,"x");'
+       cp($n,"x");
 
 =head1 DESCRIPTION