• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSFileManager and making sure you don't overwrite existing files 10.5
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSFileManager and making sure you don't overwrite existing files 10.5
      • From: Jonathan Dann <email@hidden>
References: 
 >NSFileManager and making sure you don't overwrite existing files 10.5 (From: Jonathan Dann <email@hidden>)

  • Prev by Date: Re: Creating a Cocoa Window in code
  • Next by Date: Re: NSFileManager and making sure you don't overwrite existing files 10.5
  • Previous by thread: NSFileManager and making sure you don't overwrite existing files 10.5
  • Next by thread: Re: NSFileManager and making sure you don't overwrite existing files 10.5
  • Index(es):
    • Date
    • Thread