Re: Check ability to write to nonexistent directory
Re: Check ability to write to nonexistent directory
- Subject: Re: Check ability to write to nonexistent directory
- From: Alastair Houghton <email@hidden>
- Date: Fri, 18 Jan 2008 17:29:10 +0000
On 18 Jan 2008, at 17:11, Mitchell Livingston wrote:
I would like to be able to use a function similar to NSFileManager's
isWritableFileAtPath: to determine if I can write to a certain
directory, but in this case the folder might not exist yet. For
example, a Download folder in Documents might not exist, but i would
like to be able to pass in the path and see 1. if it does exist, can
I write to it/read from it? 2. if it doesn't exist, can if be
created, and then can I write to it? Is there a function for this?
There are certainly functions you can use, but it's generally best
just to try writing to it and only then start trying to handle the
situation where you can't. Why? Because on a multitasking system
like Mac OS X, some other program could create, delete or modify the
folder you're trying to save to between your tests and your actual
write. In the worst case, this can actually create a security hole,
since it might be used by another user to cause a more privileged user
to write to the wrong place, with potentially catastrophic consequences.
Ideally, the only time you should be examining folders like this is
where you're just using the information for display purposes. e.g.
Finder's indication as to whether a folder is write-able or not.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
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