NSFileManager - a cautionary tale
NSFileManager - a cautionary tale
- Subject: NSFileManager - a cautionary tale
- From: Graham Cox <email@hidden>
- Date: Wed, 27 Jul 2011 11:14:46 +1000
Hi all, this is just a FYI really.
We've had a difficult job getting our latest app update through the App Store review, failing under section 2.3.0 which claims the we were writing to a location within the application's bundle.
The culprit turns out to be [NSFileManager createDirectoryAtPath:withIntermediateDirectories:attributes:error:]. The docs state this returns YES if the directories were created successfully, OR IF THEY EXIST ALREADY. We were relying on this second part for reading files from within the app's bundle to continue (the same code runs for both files read internally from the bundle and from an external location). However, this method eventually calls mkdir, which fails with an error if the directory already exists. This call to mkdir causes the App Store reviewers to have conniptions, even though it certainly fails. The failure of mkdir is interpreted by NSFileManager as a success (i.e. the method apparently works by attempting the mkdir, rather than checking for its existence beforehand).
While the fix is easy, understanding the problem was pretty difficult. So basically, beware this method if you use it like I was, expecting it to be safe to use on your app's bundle. You won't get past review.
--Graham
_______________________________________________
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