Re: Problem with "save as" and freed managed object context
Re: Problem with "save as" and freed managed object context
- Subject: Re: Problem with "save as" and freed managed object context
- From: Ben Trumbull <email@hidden>
- Date: Mon, 15 Mar 2010 12:52:49 -0700
> One of the other things I had been working on must have fixed the underlying problem, and my implementation of identifier and setIdentifier were actually causing this issue. I completely removed those two methods (which is of course going directly against the documentation at the top of the NSAtomicStore class reference, but going along with the implication in NSPersistentStore that you don't have to override it) and for the first time, was able to "save as"! Yay!
>
> But my elation was short lived because I now get an intermittent error on save as:
>
> Error Domain=NSCocoaErrorDomain Code=4 UserInfo=0x11e9c21c0 "The document „Untitled60.nm5‰ could not be saved as „Untitled60sa.nm5‰. The folder doesn‚t exist." Underlying Error=(Error Domain=NSCocoaErrorDomain Code=4 UserInfo=0x11ef217f0 "The folder „(null)‰ doesn‚t exist." Underlying Error=(Error Domain=NSPOSIXErrorDomain Code=2 "The operation couldn‚t be completed. No such file or directory"))
>
> So sometimes it works and sometimes it doesn't. My file format is a zipped folder with my XML files and other resources in it, so when a file is saved, I create a temporary folder and put all the bits of my file into it, zip it up, and then remove the old file and move the zipped up new one into place. I'm not sure if this is relevant at all, but when I get the save error, it also says:
>
> AppKit called rmdir("/private/var/folders/nl/nlcXN-oPHJiAXXc1Z0R5VE+++TI/TemporaryItems/(A Document Being Saved By NovaMind5TP 71)"), it didn't return 0, and errno was set to 66.
>
> But I am collecting the error messages in my app, and it's not anywhere in there, so must be from within CoreData, and the man page for rmdir just said that the return on error is >0 for errors, so I can't be certain what the error code means (I suspect it means that the folder is not empty).
Those are NSDocument errors. It has two features that may be getting in your way (or vice versa). First, the safe save functionality. It tries to marshall all the changes into a temporary directory, and then switch the document with the old one wholesale. You're removing the old file may confuse and anger the NSDocument gods, and your switching the new one may be duplicating its functionality in a way that it's not prepared for. Pretty sure you don't want to delete the old file.
The second feature is document rename tracking. NSDocument uses fs events to track any external changes to the document including renaming, deletion, or unexpected writes. By "unexpected" I mean anything that happens outside of one of NSDocument's write methods. So saving on a background thread directly against a MOC, or using FS commands to alter the document, will give NSDocument indigestion.
>
> Has anyone else seen that one before?
>
>
> I also have a problem where the save as only appears to save some of the data in my file, but I am guessing that that must be some bug in my code.
>
>
> If I open a file and then try to "save as" (without making any changes), then I get a "Could not merge changes" error message. I'm not sure if that's related to the problem where it is only saving part of the file, or is something completely different, but am planning to look at the data loss one first and see if it resolves the merge issue.
gdb:
>future-break objc_exception_throw
>future-break +[NSError errorWithDomain:code:userInfo:]
...
> info threads
> thread apply all bt
- Ben
_______________________________________________
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