Document architecture: locking document files while open
Document architecture: locking document files while open
- Subject: Document architecture: locking document files while open
- From: Matthew LeRoy <email@hidden>
- Date: Thu, 22 May 2014 15:51:19 +0000
- Thread-topic: Document architecture: locking document files while open
Good morning,
Does anyone have any idea if there is a way to get the document architecture to lock a document file when it is opened? When I say “lock”, I’m talking about an exclusive file lock at the filesystem level, as in no other user or process can open, move, or delete the file. I’m not talking about the “Locked” attribute that is settable through Finder’s Info panel or the document’s title bar menu.
The reason I ask is that my application has a corresponding Windows version, and the Windows version locks the document files when it opens them. This causes all kinds of kooky and undesired behavior if a document on a remote filesystem is first opened in the Mac version (which does not lock the file), then opened concurrently by the Windows version (which locks the file). At this point, I get all kinds of warning and error messages in the Mac application anytime autosave attempts to save the document, or if I attempt to save it manually. Unfortunately none of the messages explicitly state that the reason for the warnings and errors is that the file is locked by another user/process. Even attempting to close the document is unsuccessful if the “Ask to keep changes when closing documents” system setting is unchecked, because the application attempts to save the document, fails (because it is locked), and then aborts the close operation. The only way I have found to get out of the endless loop of warnings/errors is to choose File > Save As… and then un-check the “Keep changes in original document” checkbox.
Ideally I would like to prevent multiple users from opening a document file at the same time. The document architecture seems to automatically fail to open a file that is locked at the filesystem level, and we’ve coded that same behavior in the Windows application as well, so the only piece of the puzzle missing is getting the Mac application to lock the file once it has been successfully opened. I’m guessing I could implement the locking code manually in one of my NSDocument overrides, but I’m worried about properly handling all of the various move/rename/duplicate cases and making sure I correctly release the locks when those things happen; would be much better if the document architecture can handle all of that for me, but I don’t know if it can.
Thanks!
Matt
_______________________________________________
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