The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MacOSX::File::Copy - copy() on MacOS X

SYNOPSIS

  use MacOSX::File::Copy;
  copy($srcpath, $dstpath [,$buffersize]);
  move($srcpath, $dstpath);

DESCRIPTION

MacOSX::File::Copy provides copy() and move() as in File::Copy. Unlike File::Copy (that also comes with MacOS X), MacOSX::File::Copy preserves resouce fork and Finder attirbutes. Consider this as a perl version of CpMac and MvMac which comes with MacOS X developer kit.

EXPORT

copy() and move()

copy($from, $to, [$maxbufsize, $nocopycat])

copies file from path $from to path $to, just like File::Copy::copy(). Returns 1 on success and 0 otherwise. On error $MacOSX::File::OSErr is set when appropriate.

copy() can optionally take maximum buffer size as an argument. This value sets the limit of copy buffer. If less value is required copy() automagically allocates smaller amount of memory. When in doubt just leave it as default.

The last argument, $nocopycat tells copy() whether it should copy file attributes from the source file. File::Copy::copy does that by default but since HFS's Catalog Information is bigger than stat structure, you can save a little bit more time by setting this to 1. When set the behaviour will be more like /bin/cp with no -p option.

move($from, $to)

moves file from path $from to path $to, just like File::Copy::move(). Within same volume it uses rename(). If not it simply copy() then unlink().

This subroutine uses no xs.

AUTHOR

Dan Kogai <dankogai@dan.co.jp>

BUGS

Files w/ Unicode names now copies with no problem. FSSpec-based operations are completely gone. Now this module does pure-FSRef operation. As a result, MoreFiles is now removed from distribution.

APPENDIX -- How Darwin handles HFS+

  Here is a simple diagram of how Darwin presents HFS+ volume

               HFS+                  Darwin
  ---------------------------------------------------
  Filename:    Unicode (UCS2)        UTF-8
  Path Delim:  :                     /
               /                     :

  To implement file copy myself, I had to implement this
filename-mapping myself since file copy is done on Carbon, 
not Darwin.  Here is how.

 1.  Get FSRef of destination DIRECTORY
 2.  convert all occurance of ':' to '/' in destination BASENAME
     Since basename is still in UTF-8, it will not clobber anything.
 3.  convert the resulting basename to Unicode
 4.  Now Feed them to FSCreateFileUnicode()

  See Copy/filecopy.c for details

SEE ALSO

File::Copy CpMac(1) MvMac(1)

COPYRIGHT

Copyright 2002 Dan Kogai <dankogai@dan.co.jp>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 59:

'=item' outside of any '=over'

Around line 158:

You forgot a '=back' before '=head1'