It looks like we have a solution to the problem of the user not being able to 
restore a corrupt document from Versions Browser because the document is 
corrupt, and so she can’t open it, and so she can’t File > Revert to > Browse 
All Versions.

The solution is:

• Override -[NSDocument openDocumentWithContentsOfURL:display:error:].
• After invoking super, look in returned error for SQLite error code:11, 
'database disk image is malformed’.
• If that error is found, clear all data from the document on the disk.
• In its place, copy in data from a good, empty document.
• Invoke super again.  The document will open this time.
• Display a sheet informing user that document was corrupt and suggest File > 
Revert to > Browse All Versions.

I’ve not written the code yet, just done the above manually with a Core Data 
SQLite document that has legacy Delete/Rollback journaling.  Corruption was 
simulated by punching out the middle of the file with a hex editor.  I also 
used a hex editor to nuke and pave the document.  Result: Versions Browser 
showed previous versions of the corrupted document, as desired.  After 
restoring one, I was able to edit, save, close, and re-open it and nothing 
complained.

Happily, no reverse engineering of /.DocumentRevisions-V100 was necessary, but 
I’m still open to any better ideas.  Did I miss an easier solution to this 
problem that is built into Cocoa?

I’m aware that the magic in NS(Persistent)Document often comes back to bite 
with a vengeance days or weeks later.  I shall post again if I have any trouble.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to