Re: [MacPerl-Porters] default type/creator

[email protected] ("Scott R. Godin")
Newsgroups perl.macperl.porters
Organization Laughing Dragon Services
Message-ID <[email protected]>
In article <p05100304b7fba519a274@[10.0.1.177]>,
 [email protected] (Chris Nandor) wrote:

> In lieu of allowing some OS software to handle it, I'd suggest handling it
> somewhat manually, as Peter said.  Consider:
> 
> 	use MacPerl 'SetFileInfo';
> 	use Mac::InternetConfig;
> 
> 	$ftp->get( $remote_file, $local_file );
> 	my $map = $InternetConfigMap{$local_file};
> 	MacPerl::SetFileInfo($map->file_creator, $map->file_type, $local_file);

I do something similar when downloading the .zip files (that authors 
send us when they submit a new unreal tournament map to our site) from 
our newmaps FTP.

    if ( $file =~ m|\.zip$| )
    {
        # note: failed if function returns TRUE!
        carp "Could not change file type and creator of '$file' -- $!"
            if SetFileInfo( 'ZIP ', 'ZIP ', "$file" );
    }
    # convert to lowercase and swap spaces with _
  ( my $newfile = lc( $file ) ) =~ s|\s|\_|g;
    rename( $file, $newfile ) 
        or carp "could not rename $file to $newfile! : $!";

The trick is remembering that SetFileInfo returns backwards success 
indication.. returning TRUE means it FAILED, returning FALSE means it 
succeeded. (IMHO this is what my lil sister calls "major UGH". I'd 
suggest changing it, but it would break a lot of code. Perhaps a good 
interim fix would be to have it default to the old behaviour but have a 
switch in the use statement like use MacPerl qw/-true_on_success/; or 
something like that. ?Quien sabe?)

-- 
Scott R. Godin            | e-mail : [email protected]
Laughing Dragon Services  |    web : http://www.webdragon.net/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.