The way this is written makes it sound like there will be a call to...
Yes, and I'm actually not sure where that documentation entry actually came from, as it doesn't actually make very much sense (r.165622059). The header doc is a bit more clear:
"Disable implicitly starting access of the ephemeral security-scoped resource during resolution. Instead, call -[NSURL startAccessingSecurityScopedResource] on the returned URL when ready to use the resource. Not applicable to security-scoped bookmarks."
The key word there is "ephemeral". On macOS, there is infrastructure in place such that if an app makes a "normal" bookmark and gives it to another app, that other app has access to the file it JUST received without any additional "action". That mechanism is what "ephemeral" and "implicit" refer to. That system is better described in NSURLBookmarkCreationWithoutImplicitSecurityScope:
"Bookmarks that you create without security scope automatically carry implicit ephemeral security scope. This security scope is valid until reboot at the latest, and confers access to the resource to any other process that resolves the bookmark. Using this option prevents inclusion of this ephemeral security scope.
When using this option, other processes can’t call startAccessingSecurityScopedResource on the resolved URL. The option prevents providing unintended access to resources to other processes, and is also a performance optimization that reduces the size of the bookmark."
Returning to "NSURLBookmarkResolutionWithoutImplicitStartAccessing", the key sentence in its header doc is the combination of:
(1)
"Instead, call -[NSURL startAccessingSecurityScopedResource] on the returned URL when ready to use the resource."
...and this sentence from NSURLBookmarkCreationWithoutImplicitSecurityScope:
(2)
"This security scope is valid until reboot at the latest..."
If the ephemeral access is still valid, then startAccessingSecurityScopedResource on that URL will grant you access. If it isn't, then it won't. The problem is that WHEN it will still be active... isn't actually well defined. The "valid until reboot at the latest" is a bit of a truism as, yes, resetting the entire system does reset "everything". However, we didn't say it WOULD last that long, which is what you actually wanted to "know". I THINK the answer is that your access is actually tied to the providing apps’ accesses, but that's not formally documented nor something that can really be relied on. The ugly part here is that if IF that access has ended, then #2 can fail.
In any case, that's why:
that a subsequent pair of explicit startAccessingSecurityScopedResource and stopAccessingSecurityScopedResource will still leave access at 1, leaking kernel resources.
Is this not the case?
No, I don't think so. I believe the URL itself will end up releasing any ephemeral reference it's holding when the URL object is destroyed.
Is this consistent across macOS and iOS?
I think the behavior of this particular area should be consistent across platforms.
"This option isn’t applicable to security-scoped bookmarks."
The documentation phrasing isn't clear about whether it's talking about NSURLBookmarkResolutionWithSecurityScope specifically (which is only available on macOS).
It's not applicable to "true" security scoped bookmarks (macOS only) because both options are interacting with the same kernel structures, so including both flags would imply an odd resolution that doesn't really make sense.
or if it also applies to iOS (where all bookmarks are security scoped AFAIU from your earlier messages). Can you clarify this point?
Unfortunately, there's a breakdown in vocabulary here that's hard to explain. iOS bookmarks are security scoped in the sense that they're capable of preserving access in the same way macOS does. However, the internals of how that works are different between the two platforms.
__
Kevin Elliott
DTS Engineer, CoreOS/Hardware