Re: IsReadableFileAtPath
Re: IsReadableFileAtPath
- Subject: Re: IsReadableFileAtPath
- From: Jens Alfke <email@hidden>
- Date: Mon, 1 Mar 2010 13:24:08 -0800
On Mar 1, 2010, at 11:20 AM, gMail.com wrote:
> I have just seen that the Cocoa API isReadableFileAtPath traverses the
> symlink, so, in case the target file is not readable, my app doesn't copy
> the symlink, while the Finder can properly do. So my app does wrong.
-isReadableFileAtPath is just a convenience. If you don't want to traverse symlinks, call -fileAttributesAtPath:traverseLink: and use NO for the second parameter.
> How can I understand whether a file or symlink can really be copied?
You can't preflight file operations with 100% accuracy, because there's always a race condition — the file's permissions could be modified in between checking permission and doing the actual copy. You should still do the preflighting if it helps the user experience (by disabling a button, for example); but always be prepared to handle errors from the actual operation itself.
If you don't need preflighting for your UI, just skip it. In other words, don't do the following:
if (fileIsCopyable(file))
copyFile(file);
Instead just call copyFile() and handle any error it returns.
> And I wouldn't use the Carbon APIs because I need to compile for 64 bit.
The Carbon File Manager API is available in 64-bit, and it's perfectly appropriate to use it in Cocoa apps. It's only a subset of Carbon High-Level Toolbox APIs that aren't available in 64-bit (and you wouldn't be using those in a Cocoa app anyway.)
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden