X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FFile%2FCopy.pm;h=828473e2d3f097c97c6f22105b8ed3d06111f74e;hb=4b711db359c9778a062571f88eafc4dab0b9c81d;hp=31fad2ac5d6b2cc59cf71f522019add623d75cbf;hpb=f1442e8bd877bf75a8a6b5a6c76dbb5eea4a3b5d;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/File/Copy.pm b/lib/File/Copy.pm index 31fad2a..828473e 100644 --- a/lib/File/Copy.pm +++ b/lib/File/Copy.pm @@ -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,18 @@ require Exporter; $Too_Big = 1024 * 1024 * 2; +sub croak { + require Carp; + goto &Carp::croak; +} + +my $macfiles; +if ($^O eq 'MacOS') { + $macfiles = eval { require Mac::MoreFiles }; + warn 'Mac::MoreFiles could not be loaded; using non-native syscopy' + if $@ && $^W; +} + sub _catname { my($from, $to) = @_; if (not defined &basename) { @@ -70,13 +81,12 @@ sub copy { croak("'$from' and '$to' are identical (not copied)"); } - 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]) { + if (@ts && $fs[0] == $ts[0] && $fs[1] == $ts[1]) { croak("'$from' and '$to' are identical (not copied)"); } } @@ -173,7 +183,7 @@ sub copy { sub move { my($from,$to) = @_; - my($copied,$fromsz,$tosz1,$tomt1,$tosz2,$tomt2,$sts,$ossts); + my($fromsz,$tosz1,$tomt1,$tosz2,$tomt2,$sts,$ossts); if (-d $to && ! -d $from) { $to = _catname($from, $to); @@ -187,7 +197,6 @@ sub move { } return 1 if rename $from, $to; - ($sts,$ossts) = ($! + 0, $^E + 0); # Did rename return an error even though it succeeded, because $to # is on a remote NFS file system, and NFS lost the server's ack? return 1 if defined($fromsz) && !-e $from && # $from disappeared @@ -196,7 +205,8 @@ sub move { $tosz2 == $fromsz; # it's all there ($tosz1,$tomt1) = (stat($to))[7,9]; # just in case rename did something - return 1 if ($copied = copy($from,$to)) && unlink($from); + return 1 if copy($from,$to) && unlink($from); + ($sts,$ossts) = ($! + 0, $^E + 0); ($tosz2,$tomt2) = ((stat($to))[7,9],0,0) if defined $tomt1; unlink($to) if !defined($tomt1) or $tomt1 != $tomt2 or $tosz1 != $tosz2; @@ -230,8 +240,7 @@ unless (defined &syscopy) { return 0 unless @_ == 2; return Win32::CopyFile(@_, 1); }; - } elsif ($^O eq 'MacOS') { - require Mac::MoreFiles; + } elsif ($macfiles) { *syscopy = sub { my($from, $to) = @_; my($dir, $toname); @@ -263,17 +272,16 @@ File::Copy - Copy files or filehandles =head1 SYNOPSIS - use File::Copy; + use File::Copy; - copy("file1","file2"); - copy("Copy.pm",\*STDOUT);' + copy("file1","file2") or die "Copy failed: $!"; + 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 @@ -338,6 +346,9 @@ VMS systems, this calls the C routine (see below). For OS/2 systems, this calls the C XSUB directly. For Win32 systems, this calls C. +On Mac OS (Classic), C calls C, +if available. + =head2 Special behaviour if C is defined (OS/2, VMS and Win32) If both arguments to C are not file handles,