Re: NSFileManager and making sure you don't overwrite existing files 10.5
Re: NSFileManager and making sure you don't overwrite existing files 10.5
- Subject: Re: NSFileManager and making sure you don't overwrite existing files 10.5
- From: glenn andreas <email@hidden>
- Date: Fri, 18 Jan 2008 08:50:22 -0600
On Jan 18, 2008, at 5:46 AM, Jonathan Dann wrote:
The NSFilManager.h file says that the -fileExistsAtPath: method is
"of limited utility... encourages odd behaviour"
If I want to make sure that I'm not overwriting a file that's
already on disk then should I really try loading the file so I get
an error if it's not there?
This seems a little roundabout, are there better ways to check this?
The problem is that "make sure you aren't overwriting a file" can give
false negatives on a multi-tasking OS (and thus the comment - "man
access" for a similar but more ominous comment).
Basically, between the time you do your test and the time you actually
write the file, another process can create a file there, rendering
your test moot. And if this file is involved in some sort of security
feature, even worse things can happen (thus the "security hole" comment)
So your work around of "try to load the file to see if there is an
error" will perform no better.
A better solution to avoid overwriting a file is to save to a
temporary file and then use moveItemAtPath:toPath:error: which will
give you an error if a file already exists there.
Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
quadrium | prime : build, mutate, evolve, animate : the next
generation of fractal art
_______________________________________________
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