Commit 280c86a0f1

280c86a0f1113de7543d6fb7f171444e9611d590

parent: 722c0f5b47

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-20 08:21 UTC

Start access to picked folders before bookmarking them

A folder from SwiftUI's file importer is security-scoped, and the sandbox
refuses a bookmark of it until access starts, so Add Folder failed with
"couldn't be opened" in the Mac App Store build. Ref !402

Layout: unified · split

Sources/OrgApp/ConfigFolder.swift +2 −2
@@ -14,7 +14,7 @@ public enum ConfigFolder {
1414 var stale = false
1515 guard let url = try? URL(resolvingBookmarkData: data, options: Sandbox.bookmarkResolutionOptions(sandboxed: sandboxed), bookmarkDataIsStale: &stale) else { return nil }
1616 _ = url.startAccessingSecurityScopedResource()
17 if stale, let fresh = try? url.bookmarkData(options: Sandbox.bookmarkCreationOptions(sandboxed: sandboxed)) {
17 if stale, let fresh = try? Sandbox.bookmark(url, sandboxed: sandboxed) {
1818 defaults.set(fresh, forKey: bookmarkKey)
1919 }
2020 return url
@@ -25,7 +25,7 @@ public enum ConfigFolder {
2525 @discardableResult
2626 public static func set(_ url: URL, defaults: UserDefaults = .standard, sandboxed: Bool = Sandbox.isActive) -> Bool {
2727 _ = url.startAccessingSecurityScopedResource()
28 guard let bookmark = try? url.bookmarkData(options: Sandbox.bookmarkCreationOptions(sandboxed: sandboxed)) else { return false }
28 guard let bookmark = try? Sandbox.bookmark(url, sandboxed: sandboxed) else { return false }
2929 defaults.set(bookmark, forKey: bookmarkKey)
3030 return true
3131 }
Sources/OrgApp/FolderGrants.swift +1 −1
@@ -5,7 +5,7 @@ import OrgCore
55/// elsewhere.
66public enum SecurityBookmark {
77 public static func make(_ url: URL, sandboxed: Bool = Sandbox.isActive) -> Data? {
8 try? url.bookmarkData(options: Sandbox.bookmarkCreationOptions(sandboxed: sandboxed))
8 try? Sandbox.bookmark(url, sandboxed: sandboxed)
99 }
1010
1111 /// The bookmarked URL with access to it started, and new data when the bookmark was stale.
Sources/OrgCore/Sandbox.swift +8
@@ -25,6 +25,14 @@ public enum Sandbox {
2525 #endif
2626 }
2727
28 /// A bookmark of `url` made with `bookmarkCreationOptions`. Access to the URL is started
29 /// first: a URL from SwiftUI's file importer is security-scoped, and the sandbox refuses a
30 /// bookmark of it until access starts. Access stays on for the session.
31 public static func bookmark(_ url: URL, sandboxed: Bool = isActive) throws -> Data {
32 _ = url.startAccessingSecurityScopedResource()
33 return try url.bookmarkData(options: bookmarkCreationOptions(sandboxed: sandboxed), includingResourceValuesForKeys: nil, relativeTo: nil)
34 }
35
2836 /// The resolving side of `bookmarkCreationOptions`.
2937 public static func bookmarkResolutionOptions(sandboxed: Bool = isActive) -> URL.BookmarkResolutionOptions {
3038 #if os(macOS)
Sources/OrgWorkspace/Discovery.swift +1 −1
@@ -10,7 +10,7 @@ public struct WorkspaceRoot: Sendable, Equatable, Codable {
1010 public var path: String
1111
1212 public init(url: URL, sandboxed: Bool = Sandbox.isActive) throws {
13 bookmark = try url.bookmarkData(options: Sandbox.bookmarkCreationOptions(sandboxed: sandboxed), includingResourceValuesForKeys: nil, relativeTo: nil)
13 bookmark = try Sandbox.bookmark(url, sandboxed: sandboxed)
1414 path = url.standardizedFileURL.path
1515 }
1616