From 8bd57429237f4b262d67a88fe18ceb90cbb0d499 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 7 Dec 2019 17:53:59 -0500 Subject: [PATCH] Create helper +[PreferencesController secureBookmarkDataForURL:]. --- Source/AppDelegate.m | 8 +++----- Source/PreferencesController.h | 2 ++ Source/PreferencesController.m | 23 +++++++++++++++-------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Source/AppDelegate.m b/Source/AppDelegate.m index e665c35..cab45e7 100644 --- a/Source/AppDelegate.m +++ b/Source/AppDelegate.m @@ -132,11 +132,9 @@ continue; } if (isStale) { - NSData* newBookmark = [url bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope | NSURLBookmarkCreationSecurityScopeAllowOnlyReadAccess - includingResourceValuesForKeys:nil - relativeToURL:nil - error:&error]; - bookmarks[path] = newBookmark; + NSData* newBookmark = [PreferencesController secureBookmarkDataForURL:url]; + bookmarks[url.absoluteString] = newBookmark; + [bookmarks removeObjectForKey:path]; } if (![url startAccessingSecurityScopedResource]) { diff --git a/Source/PreferencesController.h b/Source/PreferencesController.h index dd7da37..34241fe 100644 --- a/Source/PreferencesController.h +++ b/Source/PreferencesController.h @@ -35,6 +35,8 @@ - (IBAction)addFileAccess:(id)sender; ++ (NSData*)secureBookmarkDataForURL:(NSURL*)url; + // panel switching - (IBAction)showGeneral:(id)sender; - (IBAction)showFileAccess:(id)sender; diff --git a/Source/PreferencesController.m b/Source/PreferencesController.m index ae64402..8f863d7 100644 --- a/Source/PreferencesController.m +++ b/Source/PreferencesController.m @@ -57,15 +57,9 @@ NSURL* url = panel.URL; - NSError* error; - NSData* secureBookmark = [url bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope | NSURLBookmarkCreationSecurityScopeAllowOnlyReadAccess - includingResourceValuesForKeys:nil - relativeToURL:nil - error:&error]; - if (error) { - NSLog(@"Error creating secure bookmark: %@", error); + NSData* secureBookmark = [self.class secureBookmarkDataForURL:url]; + if (!secureBookmark) return; - } NSDictionaryControllerKeyValuePair* pair = [self.fileAccessController newObject]; pair.key = url.absoluteString; @@ -73,6 +67,19 @@ [self.fileAccessController addObject:pair]; } ++ (NSData*)secureBookmarkDataForURL:(NSURL*)url +{ + NSError* error; + NSData* secureBookmark = [url bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope | NSURLBookmarkCreationSecurityScopeAllowOnlyReadAccess + includingResourceValuesForKeys:nil + relativeToURL:nil + error:&error]; + if (error) { + NSLog(@"Error creating secure bookmark: %@", error); + } + return secureBookmark; +} + #pragma mark Panel Switching /** -- 2.43.5