Strange NSFileManager file replacement issue
Strange NSFileManager file replacement issue
- Subject: Strange NSFileManager file replacement issue
- From: Sixten Otto <email@hidden>
- Date: Thu, 18 Aug 2011 21:24:41 -0700
I have an iOS app where I'm storing files in the app's Documents directory,
and occasionally downloading new versions from the server to replace them.
The actual code is split across a number of files and classes, but the end
of the process goes like this:
- The download of the new data to a temporary file in NSTemporaryDirectory()
finishes successfully.
- I calculate the path I want to copy it to.
- I see that there's already a previous version of the file at that path.
- I try to use -[NSFileManager
replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error:]
to
swap in the new file.
That method returns NO for failure, so I check the error... but it's nil.
There's nothing there to tell me what the heck is failing. (In fact, when I
wasn't initializing my error pointer to nil, it was left as a garbage
pointer, and crashed my app.) My app put the original file there, so
(presumably) that path is writable. The file manager does return true from
-fileExistsAtPath: for both files.
The only thing that Google can turn up is this StackOverflow question. Same
exact symptoms. But, of course, no answers.
http://stackoverflow.com/questions/4899618/replaceitematurl-fails-without-error-on-ios-but-works-fine-on-osx
I can *remove* the file that I can't overwrite, and I can move the temp file
into Documents in the case where there isn't already a version on disk.
Obviously, neither of those cases uses replaceItemAtURL.
Does anyone know what circumstances might cause this failure? Any
recommendations on what things I should check next?
Sixten
_______________________________________________
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