From f6f45f1a99ba79a912fce73d1ef71e60af575647 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 7 Dec 2019 17:46:03 -0500 Subject: [PATCH] Revert "For file/line breakpoints, create secure bookmarks for maintaining access." However the changes to the .entitlements file are kept. This reverts commit 1603d8d995220f0b81dcd98915f3d6c8ffe25895. Conflicts: Source/BreakpointManager.m --- Source/BSLineNumberRulerView.mm | 17 +++----- Source/Breakpoint.h | 13 ------ Source/Breakpoint.m | 77 ++------------------------------- Source/BreakpointController.m | 20 +++------ Source/BreakpointManager.m | 39 +++++------------ 5 files changed, 23 insertions(+), 143 deletions(-) diff --git a/Source/BSLineNumberRulerView.mm b/Source/BSLineNumberRulerView.mm index e912b02..7b1d253 100644 --- a/Source/BSLineNumberRulerView.mm +++ b/Source/BSLineNumberRulerView.mm @@ -141,15 +141,11 @@ const CGFloat kRulerRightPadding = 2.5; { [self computeLineIndex]; - if (lineIndex_.empty()) { - [self setRuleThickness:kDefaultWidth]; - } else { - // Determine the width of the ruler based on the line count. - NSUInteger lastElement = lineIndex_.back() + 1; - NSAttributedString* lastElementString = [self attributedStringForLineNumber:lastElement]; - NSSize boundingSize = [lastElementString size]; - [self setRuleThickness:std::max(kDefaultWidth, boundingSize.width)]; - } + // Determine the width of the ruler based on the line count. + NSUInteger lastElement = lineIndex_.back() + 1; + NSAttributedString* lastElementString = [self attributedStringForLineNumber:lastElement]; + NSSize boundingSize = [lastElementString size]; + [self setRuleThickness:std::max(kDefaultWidth, boundingSize.width)]; [self setNeedsDisplay:YES]; } @@ -213,9 +209,6 @@ const CGFloat kRulerRightPadding = 2.5; index = NSMaxRange([text lineRangeForRange:NSMakeRange(index, 0)]); } - if (lineIndex_.empty()) - return; - NSUInteger lineEnd, contentEnd; [text getLineStart:NULL end:&lineEnd diff --git a/Source/Breakpoint.h b/Source/Breakpoint.h index 4a53497..fe2e217 100644 --- a/Source/Breakpoint.h +++ b/Source/Breakpoint.h @@ -35,7 +35,6 @@ extern NSString* const kBreakpointTypeFunctionEntry; // kBreakpointTypeFile: @property (readonly) NSString* file; @property (readonly) unsigned long line; -@property (copy) NSData* secureBookmark; // kBreakpointTypeFunctionEntry: @property (readonly) NSString* functionName; @@ -51,16 +50,4 @@ extern NSString* const kBreakpointTypeFunctionEntry; // Creates a dictionary representation for use in NSUserDefaults. - (NSDictionary*)dictionary; -// For kBreakpointTypeFile: //////////////////////////////////////////////////// - -// Creates a new secure bookmark for maintaining access to the file in the App -// Sandbox across relaunches. -- (BOOL)createSecureBookmark; - -// Call to enable read-only access to the file. -- (BOOL)startSecureFileAccess; - -// Call when done accessing the file. -- (BOOL)stopSecureFileAccess; - @end diff --git a/Source/Breakpoint.m b/Source/Breakpoint.m index f3cc675..744cf5d 100644 --- a/Source/Breakpoint.m +++ b/Source/Breakpoint.m @@ -26,8 +26,6 @@ NSString* const kBreakpointTypeFunctionEntry = @"call"; unsigned long _debuggerId; NSString* _file; - NSData* _secureBookmark; - NSURL* _secureFileAccess; NSString* _functionName; } @@ -57,7 +55,6 @@ NSString* const kBreakpointTypeFunctionEntry = @"call"; _type = kBreakpointTypeFile; _file = [[dict valueForKey:@"file"] copy]; _line = [[dict valueForKey:@"line"] intValue]; - _secureBookmark = [[dict valueForKey:@"secureBookmark"] copy]; } else if ([type isEqualToString:kBreakpointTypeFunctionEntry]) { _type = kBreakpointTypeFunctionEntry; _functionName = [[dict valueForKey:@"function"] copy]; @@ -69,11 +66,6 @@ NSString* const kBreakpointTypeFunctionEntry = @"call"; return self; } -- (void)dealloc { - if (_secureFileAccess) - [self stopSecureFileAccess]; -} - /** * Returns the string to display in the breakpoints list. */ @@ -132,14 +124,11 @@ NSString* const kBreakpointTypeFunctionEntry = @"call"; - (NSDictionary*)dictionary { if (self.type == kBreakpointTypeFile) { - NSMutableDictionary* dict = [NSMutableDictionary dictionaryWithDictionary:@{ + return @{ @"type" : self.type, @"file" : self.file, - @"line" : @(self.line), - }]; - if (self.secureBookmark) - [dict setObject:self.secureBookmark forKey:@"secureBookmark"]; - return dict; + @"line" : @(self.line) + }; } else if (self.type == kBreakpointTypeFunctionEntry) { return @{ @"type" : self.type, @@ -149,66 +138,6 @@ NSString* const kBreakpointTypeFunctionEntry = @"call"; return nil; } -- (BOOL)createSecureBookmark -{ - NSURL* fileURL = [NSURL fileURLWithPath:self.file]; - return [self _createSecureBookmarkWithURL:fileURL]; -} - -- (BOOL)_createSecureBookmarkWithURL:(NSURL*)url -{ - NSError* error; - NSData* secureBookmark = [url bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope | NSURLBookmarkCreationSecurityScopeAllowOnlyReadAccess - includingResourceValuesForKeys:nil - relativeToURL:nil - error:&error]; - if (secureBookmark) { - self.secureBookmark = secureBookmark; - return YES; - } else { - NSLog(@"Failed to create secure bookmark: %@", error); - return NO; - } -} - -- (BOOL)startSecureFileAccess -{ - assert(self.type == kBreakpointTypeFile); - if (_secureFileAccess) - return YES; - if (!_secureBookmark) - return NO; - - BOOL isStale; - NSError* error; - _secureFileAccess = [NSURL URLByResolvingBookmarkData:_secureBookmark - options:NSURLBookmarkResolutionWithSecurityScope - relativeToURL:nil - bookmarkDataIsStale:&isStale - error:&error]; - if (error) { - NSLog(@"Failed to access file via secure bookmark: %@", error); - return NO; - } - if (isStale) - [self _createSecureBookmarkWithURL:_secureFileAccess]; - - return [_secureFileAccess startAccessingSecurityScopedResource]; -} - -- (BOOL)stopSecureFileAccess -{ - assert(self.type == kBreakpointTypeFile); - if (!_secureFileAccess) - return YES; - if (!_secureBookmark) - return NO; - - [_secureFileAccess stopAccessingSecurityScopedResource]; - _secureFileAccess = nil; - return YES; -} - - (NSString*)description { return [NSString stringWithFormat:@"Breakpoint %@", [[self dictionary] description]]; diff --git a/Source/BreakpointController.m b/Source/BreakpointController.m index 9e539c8..516f3a9 100644 --- a/Source/BreakpointController.m +++ b/Source/BreakpointController.m @@ -21,7 +21,6 @@ @implementation BreakpointController { BreakpointManager* _manager; - Breakpoint* _selection; BSSourceView* _sourceView; @@ -103,28 +102,19 @@ */ - (void)tableViewSelectionDidChange:(NSNotification*)notif { - if (_selection.type == kBreakpointTypeFile) { - [_selection stopSecureFileAccess]; - _selection = nil; - } - NSArray* selection = [_arrayController selectedObjects]; if ([selection count] < 1) { - [_sourceView setString:@"" asFile:nil]; - [_sourceView setMarkers:[NSSet set]]; return; } - _selection = [selection objectAtIndex:0]; - if (_selection.type != kBreakpointTypeFile) { + Breakpoint* bp = [selection objectAtIndex:0]; + if (bp.type != kBreakpointTypeFile) { return; } - [_selection startSecureFileAccess]; - - [_sourceView setFile:[_selection file]]; - [_sourceView scrollToLine:[_selection line]]; - [_sourceView setMarkers:[_manager breakpointsForFile:_selection.file]]; + [_sourceView setFile:[bp file]]; + [_sourceView scrollToLine:[bp line]]; + [_sourceView setMarkers:[_manager breakpointsForFile:bp.file]]; } @end diff --git a/Source/BreakpointManager.m b/Source/BreakpointManager.m index 2c133f6..75e6786 100644 --- a/Source/BreakpointManager.m +++ b/Source/BreakpointManager.m @@ -53,38 +53,19 @@ */ - (void)addBreakpoint:(Breakpoint*)bp; { - if ([_breakpoints containsObject:bp]) - return; - - if (bp.type == kBreakpointTypeFile && !bp.secureBookmark) { - // There is no secure bookmark for this file, so first see if any other - // bookmarks exist for the same file. If not, try and create a bookmark. - if (!bp.secureBookmark) { - [bp createSecureBookmark]; - /* - for (Breakpoint* other in _breakpoints) { - if ([other.file isEqualToString:bp.file] && other.secureBookmark) { - bp.secureBookmark = other.secureBookmark; - break; - } - } - - if (!bp.secureBookmark) { - [bp createSecureBookmark]; - } - */ - } - } + if (![_breakpoints containsObject:bp]) + { + [self willChangeValueForKey:@"breakpoints"]; + [_breakpoints addObject:bp]; + [self didChangeValueForKey:@"breakpoints"]; - [self willChangeValueForKey:@"breakpoints"]; - [_breakpoints addObject:bp]; - [self didChangeValueForKey:@"breakpoints"]; + [_connection addBreakpoint:bp]; - [_connection addBreakpoint:bp]; + [_savedBreakpoints addObject:[bp dictionary]]; + [[NSUserDefaults standardUserDefaults] setObject:_savedBreakpoints forKey:kPrefBreakpoints]; - [_savedBreakpoints addObject:[bp dictionary]]; - [[NSUserDefaults standardUserDefaults] setObject:_savedBreakpoints forKey:kPrefBreakpoints]; - [self updateDisplaysForFile:[bp file]]; + [self updateDisplaysForFile:[bp file]]; + } } - (Breakpoint*)removeBreakpoint:(Breakpoint*)bp -- 2.43.5