Wrap access of itemUrl in security scoping
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 17 Apr 2024 20:55:14 +0000 (04:55 +0800)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Thu, 18 Apr 2024 05:13:11 +0000 (05:13 +0000)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareViewController.swift

index e6d969e85bc819bb3e0ff6f79d2b47a9198be897..058708a653d9f7060c7af826efb9a98cfc9d1c9e 100644 (file)
@@ -47,6 +47,13 @@ class ShareViewController: NSViewController, ShareViewDataSourceUIDelegate {
             return
         }
 
+        Logger.shareViewController.info(
+            """
+            Instantiated with itemIdentifiers: 
+            \(itemIdentifiers.map { $0.rawValue }, privacy: .public)
+            """
+        )
+
         Task {
             await processItemIdentifier(firstItem)
         }
@@ -72,11 +79,16 @@ class ShareViewController: NSViewController, ShareViewDataSourceUIDelegate {
 
         do {
             let itemUrl = try await manager.getUserVisibleURL(for: itemIdentifier)
+            guard itemUrl.startAccessingSecurityScopedResource() else {
+                Logger.shareViewController.error("Could not access scoped resource for item url!")
+                return
+            }
             await updateDisplay(itemUrl: itemUrl)
             shareDataSource.uiDelegate = self
             shareDataSource.sharesTableView = tableView
             shareDataSource.loadItem(url: itemUrl)
             optionsView.dataSource = shareDataSource
+            itemUrl.stopAccessingSecurityScopedResource()
         } catch let error {
             let errorString = "Error processing item: \(error)"
             Logger.shareViewController.error("\(errorString, privacy: .public)")