develooper Front page | perl.perl5.porters | Postings from February 2001

[PATCH] File::Copy for bleadperl, maintperl

Thread Next
From:
Chris Nandor
Date:
February 28, 2001 19:10
Subject:
[PATCH] File::Copy for bleadperl, maintperl
Message ID:
p05010400b6c36d959ae8@[10.0.1.177]
--- lib/File/Copy.pm.orig	Fri Feb 23 16:43:47 2001
+++ lib/File/Copy.pm	Wed Feb 28 20:21:47 2001
@@ -37,7 +37,7 @@
 	import  File::Basename 'basename';
     }
     if ($^O eq 'VMS')  { $to = VMS::Filespec::vmspath($to) . basename($from); }
-    elsif ($^O eq 'MacOS') { $to .= ':' . basename($from); }
+    elsif ($^O eq 'MacOS') { $to =~ s/^([^:]+)$/:$1/; $to .= ':' . basename($from); }
     elsif ($to =~ m|\\|)   { $to .= '\\' . basename($from); }
     else                   { $to .= '/' . basename($from); }
 }
@@ -69,6 +69,7 @@
 	&& !($from_a_handle && $^O eq 'os2' )	# OS/2 cannot handle handles
 	&& !($from_a_handle && $^O eq 'mpeix')	# and neither can MPE/iX.
 	&& !($from_a_handle && $^O eq 'MSWin32')
+	&& !($from_a_handle && $^O eq 'MacOS')
        )
     {
 	return syscopy($from, $to);
@@ -83,7 +84,7 @@
     if ($from_a_handle) {
 	*FROM = *$from{FILEHANDLE};
     } else {
-	$from = "./$from" if $from =~ /^\s/s;
+	$from = _protect($from) if $from =~ /^\s/s;
 	open(FROM, "< $from\0") or goto fail_open1;
 	binmode FROM or die "($!,$^E)";
 	$closefrom = 1;
@@ -92,7 +93,7 @@
     if ($to_a_handle) {
 	*TO = *$to{FILEHANDLE};
     } else {
-	$to = "./$to" if $to =~ /^\s/s;
+	$to = _protect($to) if $to =~ /^\s/s;
 	open(TO,"> $to\0") or goto fail_open2;
 	binmode TO or die "($!,$^E)";
 	$closeto = 1;
@@ -180,6 +181,13 @@
 *cp = \&copy;
 *mv = \&move;
 
+
+if ($^O eq 'MacOS') {
+    *_protect = sub { MacPerl::MakeFSSpec($_[0]) };
+} else {
+    *_protect = sub { "./$_[0]" };
+}
+
 # &syscopy is an XSUB under OS/2
 unless (defined &syscopy) {
     if ($^O eq 'VMS') {
@@ -195,6 +203,23 @@
 	*syscopy = sub {
 	    return 0 unless @_ == 2;
 	    return Win32::CopyFile(@_, 1);
+	};
+    } elsif ($^O eq 'MacOS') {
+	require Mac::MoreFiles;
+	*syscopy = sub {
+	    my($from, $to) = @_;
+	    my($dir, $toname);
+
+	    return 0 unless -e $from;
+
+	    if ($to =~ /(.*:)([^:]+):?$/) {
+		($dir, $toname) = ($1, $2);
+	    } else {
+		($dir, $toname) = (":", $to);
+	    }
+
+	    unlink($to);
+	    Mac::MoreFiles::FSpFileCopy($from, $dir, $toname, 1);
 	};
     } else {
 	$Syscopy_is_copy = 1;
-- 
Chris Nandor                      pudge@pobox.com    http://pudge.net/
Open Source Development Network    pudge@osdn.com     http://osdn.com/

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About