Re: Does "- replaceItemAtURL: withItemAtURL: backupItemName: options: resultingItemURL: error:" handle cross-volume moves?
Re: Does "- replaceItemAtURL: withItemAtURL: backupItemName: options: resultingItemURL: error:" handle cross-volume moves?
- Subject: Re: Does "- replaceItemAtURL: withItemAtURL: backupItemName: options: resultingItemURL: error:" handle cross-volume moves?
- From: Marc Khadpe <email@hidden>
- Date: Mon, 30 Mar 2015 19:55:12 -0400
> On Mar 30, 2015, at 7:44 PM, Daryle Walker <email@hidden <mailto:email@hidden>> wrote:
>
> NSFileManager’s “- moveItemAtURL: toURL: error:” method does a copy if the source and destination file-URLs are on different volumes. Does “- replaceItemAtURL: withItemAtURL: backupItemName: options: resultingItemURL: error:” do similar? The docs for the latter don’t mention it. I’m worried since those docs do mention temporary directories, that we have to do different-volume detection (possibly harder than in the pre-X days) and copying manually. I don’t want to do that, since Apple already includes that logic in the former method.
My experience on Yosemite is that NSFileManager’s “replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error:” method fails if the source and destination URLs are not on the same volume. The correct procedure, as I understand it, is to first create a temporary file using "URLForDirectory: inDomain:appropriateForURL:create:error:”, supplying NSItemReplacementDirectory for the directory parameter, NSUserDomain for the domain, and the destination URL as the URL. This will create a temporary directory on the same volume as the supplied URL in which you can then create your temp file. Then you can use the replaceItemAtURL method to replace the file contents. If you use NSTemporaryDirectory() instead of URLForDirectory, your temp file could end up on a different volume then the destination, and replaceItemAtURL may fail.
Marc Khadpe
_______________________________________________
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