Manual integration error in #12235.
[p5sagit/p5-mst-13.2.git] / lib / File / Copy.pm
index fb57a9e..afb7635 100644 (file)
@@ -7,11 +7,12 @@
 
 package File::Copy;
 
-use 5.6.0;
+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);
 sub copy;
 sub syscopy;
@@ -23,7 +24,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.04';
+$VERSION = '2.05';
 
 require Exporter;
 @ISA = qw(Exporter);
@@ -65,6 +66,21 @@ sub copy {
                             || UNIVERSAL::isa($to, 'IO::Handle'))
                         : (ref(\$to) eq 'GLOB'));
 
+    if ($from eq $to) { # works for references, too
+       croak("'$from' and '$to' are identical (not copied)");
+    }
+
+    if ($Config{d_symlink} && $Config{d_readlink} &&
+       !($^O eq 'Win32' || $^O eq 'os2' || $^O eq 'vms')) {
+       if ((-e $from && -l $from) || (-e $to && -l $to)) {
+           my @fs = stat($from);
+           my @ts = stat($to);
+           if (@fs && @ts && $fs[0] == $ts[0] && $fs[1] == $ts[1]) {
+               croak("'$from' and '$to' are identical (not copied)");
+           }
+       }
+    }
+
     if (!$from_a_handle && !$to_a_handle && -d $to && ! -d $from) {
        $to = _catname($from, $to);
     }
@@ -275,7 +291,8 @@ argument may be a string, a FileHandle reference or a FileHandle
 glob. Obviously, if the first argument is a filehandle of some
 sort, it will be read from, and if it is a file I<name> it will
 be opened for reading. Likewise, the second argument will be
-written to (and created if need be).
+written to (and created if need be).  Trying to copy a file on top
+of itself is a fatal error.
 
 B<Note that passing in
 files as handles instead of names may lead to loss of information