[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Deleting files & interaction with AppleScript



At 13.52 -0500 1999.01.16, (Prymmer/Kahn) wrote:
>Does catfile() take care of both data and resource forks on MacOS?

Catfile concatenates directories with a filename.  So:

  File::Spec->catfile(qw(a b c d e f g));

Returns on a Mac:

  a:b:c:d:e:f:g

And on Unix:

  /a/b/c/d/e/f/g

And similarly, File::Spec->catdir(qw(a b c d e f g)) returns on a Mac:

  a:b:c:d:e:f:g:

And on Unix:

  /a/b/c/d/e/f/g/

So this:

    foreach $src_file (@src_files) {
        if ($Is_MacOS) {
            $src_path = "$src_dir:$src_file";
            $dest_path = "$dest_dir:$src_file";
        }
        else {
            $src_path = "$src_dir/$src_file";
            $dest_path = "$dest_dir/$src_file";
        }

Would become this:

    foreach $src_file (@src_files) {
        $src_path = File::Spec->($src_dir, $src_file);

Then File::Copy::copy would take care of copying the file properly.
File::Copy uses Mac::Files::FSpFileCopy() for copying files on Mac, which
takes care of the resource and data forks.

Note that while this should ideally work on older installations, users of
older installations can use File::Spec.  In fact, perl5.005 pumpking Graham
Barr recently gave an endorsement to have my patches to CPAN.pm use
File::Spec.  If you want, though, a reasonable alternative is to combine
the two approaches:

    local($haveFileSpec) = do 'File/Spec.pm';

    # ....

    foreach $src_file (@src_files) {
        if ($haveFileSpec) {
            $src_path = File::Spec->($src_dir, $src_file);
        } else {
            if ($Is_MacOS) {
                $src_path = "$src_dir:$src_file";
                $dest_path = "$dest_dir:$src_file";
            }
            else {
                $src_path = "$src_dir/$src_file";
                $dest_path = "$dest_dir/$src_file";
            }
        }

That way you make sure you do the right thing if File::Spec is installed
(assuming a proper File::Spec:: module exists for the platform), and you do
your best to do the right thing if it is not.  Clark Cooper does not want
to require File::Spec to search for encoding files in XML::Parser, and
rather than rewrite how he finds the files, I changed the paths to be done
with File::Spec if present, else assume Unix-style paths.  Hopefully he'll
accept the patch.  :)

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch