Re: checking if directory is writable
Re: checking if directory is writable
- Subject: Re: checking if directory is writable
- From: Wade Tregaskis <email@hidden>
- Date: Thu, 12 Jan 2012 22:25:00 -0800
> I was of the understanding that Apple's recommendation was just to try the operation you wanted to perform, and handle the error if there is one. This is taken from the NSFileManager header, directly above the isWriteableAtPath: declaration:
>
> "The following methods are of limited utility. Attempting to predicate behavior based on the current state of the filesystem or a particular file on the filesystem is encouraging odd behavior in the face of filesystem race conditions. It's far better to attempt an operation (like loading a file or creating a directory) and handle the error gracefully than it is to try to figure out ahead of time whether the operation will succeed."
There's a tendency to create a false dichotomy there, though. It's true that only checking in advance is erroneous, but advanced checks can be useful if done appropriately. For example, when the user first selects a file you could sanity check it, and if it looks like something is wrong you can subtly warn the user. The key is to not stop them actually trying - the only true gauge is whether the real operation succeeds or not - and not to be too invasive. For example, think about the standard Open dialog which by default disables files of unsupported formats. Or the variant of the same which doesn't disable them, but shows a passive warning message within the dialog window if you select one.
It's not something to be considered too lightly, though, because to do a really good job of it takes more work than you might think. For example, if you're going to indicate that the user can't seemingly write to the target folder, you really should be watching that folder for changes. When it does become readable, you can remove the warning immediately, providing clear feedback to the user that a) they've fixed the issue correctly, and b) your app is paying attention. Think about installers that require you to quit certain open apps, and compare the ones that make you re-run the installer manually versus those that will get immediately underway as soon as the apps are closed.
_______________________________________________
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