Re: NSDoc's Magic File Watcher Ruins Core Data Migration [SOLVED]
Re: NSDoc's Magic File Watcher Ruins Core Data Migration [SOLVED]
- Subject: Re: NSDoc's Magic File Watcher Ruins Core Data Migration [SOLVED]
- From: Chris Parker <email@hidden>
- Date: Mon, 24 May 2010 14:44:33 -0700
Hi Jerry,
On 24 May 2010, at 2:29 PM, Jerry Krinock wrote:
> I did as Quincey suggested and it fixed the bug in my multi-stage automatic migration.
>
> Indeed, FSExchangeObjects() is documented as:
>
> "... allows programs to implement a “safe save” operation by creating and writing a complete new file and swapping the contents. An alias, FSSpec, or FSRef that refers to the old file will now access the new data. ..."
>
> Now that is indeed quite useful, and just what I needed. I wonder why Apple didn't provide a Cocoa wrapper for FSExchangeObjects() in NSFileManager? Maybe they want us appreciate Quincey some more.
Apple did. I believe it was even mentioned in the release notes for SnowLeopard. Here's the method declaration from NSFileManager.h:
/* -replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error: is for developers who wish to perform a safe-save without using the full NSDocument machinery that is available in the AppKit.
The `originalItemURL` is the item being replaced.
`newItemURL` is the item which will replace the original item. This item should be placed in a temporary directory as provided by the OS, or in a uniquely named directory placed in the same directory as the original item if the temporary directory is not available.
If `backupItemName` is provided, that name will be used to create a backup of the original item. The backup is placed in the same directory as the original item. If an error occurs during the creation of the backup item, the operation will fail. If there is already an item with the same name as the backup item, that item will be removed. The backup item will be removed in the event of success unless the `NSFileManagerItemReplacementWithoutDeletingBackupItem` option is provided in `options`.
For `options`, pass `0` to get the default behavior, which uses only the metadata from the new item while adjusting some properties using values from the original item. Pass `NSFileManagerItemReplacementUsingNewMetadataOnly` in order to use all possible metadata from the new item.
*/
- (BOOL)replaceItemAtURL:(NSURL *)originalItemURL withItemAtURL:(NSURL *)newItemURL backupItemName:(NSString *)backupItemName options:(NSFileManagerItemReplacementOptions)options resultingItemURL:(NSURL **)resultingURL error:(NSError **)error AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
.chris
--
Chris Parker
iPhone Frameworks
Apple Inc.
_______________________________________________
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