Re: CoreData migration opens ~ file by mistake
Re: CoreData migration opens ~ file by mistake
- Subject: Re: CoreData migration opens ~ file by mistake
- From: Michael Link <email@hidden>
- Date: Mon, 21 Mar 2011 23:28:20 -0500
I'm running into this same problem on 10.6 when the migration is automatic or manual. I can always reproduce it with manual migration.
After migration and the document window is open and the application is made inactive and active again you may notice the title of the document has suddenly changed to the backup file with the ~ before the extension. It appears that the magic file watching behavior of NSDocument decides to switch back to the backup file which typically causes unexpected behavior.
#0 0x100002fb9 in -[MyDocument setFileURL:] at MyDocument.m:556
#1 0x7fff80b0fdcc in -[NSDocument _handleDocumentFileChanges:]
#2 0x7fff887c67b4 in -[NSArray makeObjectsPerformSelector:withObject:]
#3 0x7fff8329523c in __NSFireDelayedPerform
#4 0x7fff887b1be8 in __CFRunLoopRun
#5 0x7fff887afdbf in CFRunLoopRunSpecific
#6 0x7fff854cc93a in RunCurrentEventLoopInMode
#7 0x7fff854cc69d in ReceiveNextEventCommon
#8 0x7fff854cc5f8 in BlockUntilNextEventMatchingListInMode
#9 0x7fff80939e64 in _DPSNextEvent
#10 0x7fff809397a9 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
#11 0x7fff808ff48b in -[NSApplication run]
#12 0x7fff808f81a8 in NSApplicationMain
#13 0x10000e7f5 in main at main.m:27
I've fixed this in my manual migration by using FSExchangeObjects(). Unfortunately the docs say that it only works on HFS+ and AppleShares... and perhaps you don't like to make assumptions about where people store their data.
I've also fixed this by using NSFileManager's -replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error:
This appears to work if you don't use the NSFileManagerItemReplacementWithoutDeletingBackupItem option. If you do then you will need to know where the backup file is located and add this method to your NSDocument subclass.
- (void)setFileURL:(NSURL*)absoluteURL
{
if ([absoluteURL isEqual:_backupURL]) {
[super setFileURL:[self fileURL]];
return;
}
[super setFileURL:absoluteURL];
}
--
Michael
On Feb 22, 2011, at 10:36 PM, Jim Thomason wrote:
> I'm finally trying to do my first CoreData migration using the "new"
> style 10.5 built-in migration tools. I'd abandoned my ad-hoc Tiger one
> a while back and finally needed to migrate.
>
> I'm building on Snow Leopard, and bugs and glitches aside (such as the
> workaround for migration for Leopard deployment built on Snow
> Leopard), it's mostly working. But what it boils down to is when I
> deploy it on Leopard, the migration is correctly performed, but then
> the app insists upon re-opening the foo~.ext file (the backup with the
> tilde) instead of the actual upgraded data file itself. The simple
> solution is just to shut the doc w/o saving, then re-open it. All
> problems solved when I do that, but I don't really want to ask my
> users to do it.
>
> It behaves just fine on Snow Leopard.
>
> I found some old posts referencing the issue, such as:
> http://lists.apple.com/archives/cocoa-dev/2009/Nov/msg01431.html
>
> But no functional solutions. I tried implementing mmalc's custom
> NSDocumentController subclass, but the issue persisted. So I dropped
> it out and left just the standard modification to
> configurePersistentStoreCoordinatorForURL: to turn on
> forKey:NSMigratePersistentStoresAutomaticallyOption.
>
> Sometimes the ~ pops up in the title bar, sometimes it doesn't. The
> doc is never actually save-able.
>
> Did anyone ever discover a viable solution?
>
> -Jim....
> _______________________________________________
>
> 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
>
>
_______________________________________________
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