• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
document inexplicably becomes locked and fails to save under sandboxing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

document inexplicably becomes locked and fails to save under sandboxing


  • Subject: document inexplicably becomes locked and fails to save under sandboxing
  • From: Martin Wierschin <email@hidden>
  • Date: Tue, 10 Jun 2014 22:18:00 -0700

Hello everyone,

I'm sandboxing an NSDocument based application for OS X. In addition to Apple's standard Open Recent menu, this app also provides the user a few ways to reopen commonly used documents. To make that work under sandboxing, I capture a security-scoped bookmark for each such document. Then later, when the users wants to reopen the file, I resolve that bookmark data back to a URL. The code is something like:

	NSData* bookmark = XXLoadDocumentBookmarkData();
	NSURLBookmarkResolutionOptions ops = NSURLBookmarkResolutionWithSecurityScope;
	NSURL* url = [NSURL URLByResolvingBookmarkData:bookmark options:ops relativeToURL:nil bookmarkDataIsStale:NULL error:NULL];

	[url startAccessingSecurityScopedResource];
	NSDocument* doc = [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:url display:YES error:NULL];
	[url stopAccessingSecurityScopedResource];

Anyways, that code works just fine: the document is reopened with proper read/write access.

The problem is that after some period of time, the reopened documents become locked and saving fails. Both autosave and manual save operations fail with the error: "you don’t own the file and don't have permission to write to it". In the document's titlebar the suffix "— Locked" is shown, and Cocoa prevents me from unlocking the document using the popup options. The issue never occurs immediately, only after some successful saves and perhaps a few minutes have passed. I have discerned no pattern to when or what triggers the locking.

Does anyone have any idea what's going wrong? Why is sandbox access for these documents being cut off while they remain open?

I can somewhat workaround the problem by overriding -[NSDocument performSynchronousFileAccessUsingBlock:], wrapping super's implementation with -[NSURL startAccessingSecurityScopedResource] for the relevant URL. However, that feels like a hack and makes me very nervous that other things could be broken. Also, while that restores successful saving, it doesn't prevent "— Locked" from appearing in the document's titlebar.

Thank you for any ideas or help!

Best,
Martin Wierschin


_______________________________________________

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


  • Follow-Ups:
    • Re: document inexplicably becomes locked and fails to save under sandboxing
      • From: SevenBits <email@hidden>
  • Prev by Date: Re: Another app's UTI can break your app
  • Next by Date: UIKit and Swift
  • Previous by thread: Re: CMMotionManager valid data?
  • Next by thread: Re: document inexplicably becomes locked and fails to save under sandboxing
  • Index(es):
    • Date
    • Thread