Re: Odd initial save behavior with bundle based NSDocument
Re: Odd initial save behavior with bundle based NSDocument
- Subject: Re: Odd initial save behavior with bundle based NSDocument
- From: Neil Clayton <email@hidden>
- Date: Thu, 22 Mar 2012 10:10:45 +1300
Hi Mike,
I was about to post code + screenshots showing I had checked all this (which I thought I had).
In doing so I found out of course that the autosave mechanism was in fact saving all over the show. Given that we are managing the assets manually (they are large, possible GBs in size, hence not using a file wrapper), that was the issue. New projects would be written - assets were not moved (because no previous autosave URL or project URL was available in this case), and we'd be left with a somewhat empty project.
So, I just made the write: move the assets appropriately if no original autosave location was found. Seems to work OK for new docs, saving existing, duplication.
Thanks for the question: you got me looking in the right place!
--
Neil
On 22/03/2012, at 12:30 AM, Mike Abdullah wrote:
> It sounds to me like your writeToURL… method isn't writing out the entire document's contents. Can you show us some code? Note that for document packages, using NSFileWrapper often makes your implementation a lot easier.
>
> Sent from my iPad
>
> On 20 Mar 2012, at 07:53 PM, Neil Clayton <email@hidden> wrote:
>
>> Hi All,
>>
>> I'm seeing something a bit odd with NSDocument in 10.7.
>>
>> We're writing large files to our own package, so as a result I've overridden:
>>
>> - (BOOL) writeToURL:ofType:forSaveOperation:originalContentsURL:error:
>> - (BOOL)readFromURL:ofType:error:
>>
>> + (BOOL) autosavesInPlace - is fixed to return YES.
>>
>> We have a single index file at the root of the bundle, plus a subfolder called "assets", which while initially empty will get filled with files as we "do stuff" with the document. Note: the addition of files to this folder can and does occur outside of specific calls to the document.
>>
>> Now, what I'm seeing is this:
>>
>> 1) Make a new doc
>> 2) Put some additional files within the assets folder of the doc
>> 3) Save the new (presently Untitled) doc to the Desktop
>> 4) Result: The saved doc *no longer contains the asset file*
>>
>> What I understand (according to the NSDocument headers) is that writeSafelyToURL:ofType:forSaveOperation:error: is supposed to do "a bunch-o-stuff" (as outlined in the headers). And, importantly, at the end
>>
>> " 4) Moves the just-written file to its final location, or deletes the old on-disk revision of the document, and deletes any temporary directories, depending on the same factors listed for step 1."
>>
>> I can see our write call made, to the unsaved doc in ~/Library/Autosave Information/. If I open this bundle in Finder, the contents are saved just fine, and there is a single asset in the assets folder. This is expected.
>>
>> However; it doesn't get moved (point 4 above) correctly.
>> When I open the moved document on the Desktop, it's got it's index file, and an assets folder, but there are NO assets inside that folder. It's like the move operation moved everything at level 1, and didn't take into account subfolders.
>>
>>
>> Any ideas?
>>
>> --
>> Neil Clayton
>>
>>
>>
>>
>>
>> _______________________________________________
>>
>> 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
Neil Clayton
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