From 115686cd07beceeeb923f22fbcc62af7876786b8 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 27 Aug 2016 01:09:24 -0400 Subject: [PATCH] Change dmg and test verifying code by removing NTSynchronousTask --- Sparkle.xcodeproj/project.pbxproj | 16 --- Sparkle/SUBinaryDeltaUnarchiver.m | 1 - Sparkle/SUDiskImageUnarchiver.m | 39 ++++-- Tests/SUCodeSigningVerifierTest.m | 19 +-- Vendor/CocoatechCore/NTSynchronousTask.h | 26 ---- Vendor/CocoatechCore/NTSynchronousTask.m | 169 ----------------------- 6 files changed, 40 insertions(+), 230 deletions(-) delete mode 100644 Vendor/CocoatechCore/NTSynchronousTask.h delete mode 100644 Vendor/CocoatechCore/NTSynchronousTask.m diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 6f7c8a4b..87532d22 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -105,7 +105,6 @@ 6102FE4A0E07803800F85D09 /* SUDiskImageUnarchiver.h in Headers */ = {isa = PBXBuildFile; fileRef = 6102FE480E07803800F85D09 /* SUDiskImageUnarchiver.h */; settings = {ATTRIBUTES = (); }; }; 6102FE4B0E07803800F85D09 /* SUDiskImageUnarchiver.m in Sources */ = {isa = PBXBuildFile; fileRef = 6102FE490E07803800F85D09 /* SUDiskImageUnarchiver.m */; }; 6102FE5B0E08C7EC00F85D09 /* SUUnarchiver_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 6102FE590E08C7EC00F85D09 /* SUUnarchiver_Private.h */; settings = {ATTRIBUTES = (); }; }; - 610EC1E00CF3A5FE00AE239E /* NTSynchronousTask.m in Sources */ = {isa = PBXBuildFile; fileRef = 610EC1BF0CF3914D00AE239E /* NTSynchronousTask.m */; }; 611142E910FB1BE5009810AA /* bspatch.h in Headers */ = {isa = PBXBuildFile; fileRef = 611142E810FB1BE5009810AA /* bspatch.h */; }; 61177A1F0D1112E900749C97 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6117796E0D1112E000749C97 /* IOKit.framework */; }; 61180BCA0D64138900B4E0D1 /* SUWindowController.h in Headers */ = {isa = PBXBuildFile; fileRef = 61180BC80D64138900B4E0D1 /* SUWindowController.h */; settings = {ATTRIBUTES = (); }; }; @@ -123,7 +122,6 @@ 612DCBB00D488BC60015DBEA /* SUUpdatePermissionPrompt.m in Sources */ = {isa = PBXBuildFile; fileRef = 612DCBAE0D488BC60015DBEA /* SUUpdatePermissionPrompt.m */; }; 6158A1C5137904B300487EC1 /* SUUpdater_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 6158A1C4137904B300487EC1 /* SUUpdater_Private.h */; }; 615AE3D00D64DC40001CA7BD /* SUModelTranslation.plist in Resources */ = {isa = PBXBuildFile; fileRef = 615AE3CF0D64DC40001CA7BD /* SUModelTranslation.plist */; }; - 6160E7E10D3B4A8800E9CD71 /* NTSynchronousTask.h in Headers */ = {isa = PBXBuildFile; fileRef = 610EC1C00CF3914D00AE239E /* NTSynchronousTask.h */; settings = {ATTRIBUTES = (); }; }; 618FA5010DAE88B40026945C /* SUInstaller.h in Headers */ = {isa = PBXBuildFile; fileRef = 618FA4FF0DAE88B40026945C /* SUInstaller.h */; settings = {ATTRIBUTES = (); }; }; 618FA5020DAE88B40026945C /* SUInstaller.m in Sources */ = {isa = PBXBuildFile; fileRef = 618FA5000DAE88B40026945C /* SUInstaller.m */; }; 618FA5050DAE8AB80026945C /* SUPlainInstaller.h in Headers */ = {isa = PBXBuildFile; fileRef = 618FA5030DAE8AB80026945C /* SUPlainInstaller.h */; settings = {ATTRIBUTES = (); }; }; @@ -569,8 +567,6 @@ 6102FE480E07803800F85D09 /* SUDiskImageUnarchiver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUDiskImageUnarchiver.h; sourceTree = ""; }; 6102FE490E07803800F85D09 /* SUDiskImageUnarchiver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUDiskImageUnarchiver.m; sourceTree = ""; }; 6102FE590E08C7EC00F85D09 /* SUUnarchiver_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUnarchiver_Private.h; sourceTree = ""; }; - 610EC1BF0CF3914D00AE239E /* NTSynchronousTask.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NTSynchronousTask.m; sourceTree = ""; }; - 610EC1C00CF3914D00AE239E /* NTSynchronousTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NTSynchronousTask.h; sourceTree = ""; }; 611142E810FB1BE5009810AA /* bspatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bspatch.h; sourceTree = ""; }; 61131A050F846CE600E97AF6 /* da */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = da; path = da.lproj/Sparkle.strings; sourceTree = ""; }; 61131A090F846D0A00E97AF6 /* zh_CN */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = zh_CN; path = zh_CN.lproj/Sparkle.strings; sourceTree = ""; }; @@ -897,7 +893,6 @@ isa = PBXGroup; children = ( 14732BB61960ECE800593899 /* bsdiff */, - 14732BB71960ECF000593899 /* CocoatechCore */, ); name = "Third Party"; path = Vendor; @@ -917,15 +912,6 @@ path = bsdiff; sourceTree = ""; }; - 14732BB71960ECF000593899 /* CocoatechCore */ = { - isa = PBXGroup; - children = ( - 610EC1C00CF3914D00AE239E /* NTSynchronousTask.h */, - 610EC1BF0CF3914D00AE239E /* NTSynchronousTask.m */, - ); - path = CocoatechCore; - sourceTree = ""; - }; 14732BB81960EEB600593899 /* Resources */ = { isa = PBXGroup; children = ( @@ -1247,7 +1233,6 @@ buildActionMask = 2147483647; files = ( 611142E910FB1BE5009810AA /* bspatch.h in Headers */, - 6160E7E10D3B4A8800E9CD71 /* NTSynchronousTask.h in Headers */, 61299B3609CB04E000B7442F /* Sparkle.h in Headers */, 61CFB3290E385186007A1735 /* Sparkle.pch in Headers */, 61B5FC0D09C4FC8200B25A18 /* SUAppcast.h in Headers */, @@ -1801,7 +1786,6 @@ files = ( 5D06E8EB0FD68CE4005AE3F6 /* bspatch.c in Sources */, 722954C51D04E66F00ECF9CA /* SUFileOperationConstants.m in Sources */, - 610EC1E00CF3A5FE00AE239E /* NTSynchronousTask.m in Sources */, 61B5FBB709C4FAFF00B25A18 /* SUAppcast.m in Sources */, 61B5FC6F09C51F4900B25A18 /* SUAppcastItem.m in Sources */, 6120721309CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.m in Sources */, diff --git a/Sparkle/SUBinaryDeltaUnarchiver.m b/Sparkle/SUBinaryDeltaUnarchiver.m index 7d1e1496..e9990e65 100644 --- a/Sparkle/SUBinaryDeltaUnarchiver.m +++ b/Sparkle/SUBinaryDeltaUnarchiver.m @@ -12,7 +12,6 @@ #import "SUUnarchiver_Private.h" #import "SUHost.h" #import "SULog.h" -#import "NTSynchronousTask.h" @implementation SUBinaryDeltaUnarchiver diff --git a/Sparkle/SUDiskImageUnarchiver.m b/Sparkle/SUDiskImageUnarchiver.m index 31a1b5ec..0b8f8f92 100644 --- a/Sparkle/SUDiskImageUnarchiver.m +++ b/Sparkle/SUDiskImageUnarchiver.m @@ -8,7 +8,6 @@ #import "SUDiskImageUnarchiver.h" #import "SUUnarchiver_Private.h" -#import "NTSynchronousTask.h" #import "SULog.h" #include @@ -89,12 +88,26 @@ NSInteger taskResult = -1; @try { - NTSynchronousTask *task = [[NTSynchronousTask alloc] init]; - - [task run:@"/usr/bin/hdiutil" directory:@"/" withArgs:arguments input:promptData]; - - taskResult = [task result]; - output = [[task output] copy]; + NSTask *task = [[NSTask alloc] init]; + task.launchPath = @"/usr/bin/hdiutil"; + task.currentDirectoryPath = @"/"; + task.arguments = arguments; + + NSPipe *inputPipe = [NSPipe pipe]; + NSPipe *outputPipe = [NSPipe pipe]; + + task.standardInput = inputPipe; + task.standardOutput = outputPipe; + + [task launch]; + + [inputPipe.fileHandleForWriting writeData:promptData]; + [inputPipe.fileHandleForWriting closeFile]; + + [task waitUntilExit]; + + output = [outputPipe.fileHandleForReading readDataToEndOfFile]; + taskResult = task.terminationStatus; } @catch (NSException *) { @@ -144,10 +157,16 @@ dispatch_async(dispatch_get_main_queue(), delegateFailure); finally: - if (mountedSuccessfully) - [NSTask launchedTaskWithLaunchPath:@"/usr/bin/hdiutil" arguments:@[@"detach", mountPoint, @"-force"]]; - else + if (mountedSuccessfully) { + @try { + [NSTask launchedTaskWithLaunchPath:@"/usr/bin/hdiutil" arguments:@[@"detach", mountPoint, @"-force"]]; + } @catch (NSException *exception) { + SULog(@"Failed to unmount %@", mountPoint); + SULog(@"Exception: %@", exception); + } + } else { SULog(@"Can't mount DMG %@", self.archivePath); + } } } diff --git a/Tests/SUCodeSigningVerifierTest.m b/Tests/SUCodeSigningVerifierTest.m index 40aa79ac..045a128f 100644 --- a/Tests/SUCodeSigningVerifierTest.m +++ b/Tests/SUCodeSigningVerifierTest.m @@ -8,7 +8,6 @@ #import #import -#import "NTSynchronousTask.h" #import "SUCodeSigningVerifier.h" #import "SUFileManager.h" @@ -124,10 +123,14 @@ BOOL success = NO; @try { - NTSynchronousTask *task = [[NTSynchronousTask alloc] init]; - NSArray *arguments = @[ zipPath ]; - [task run:@"/usr/bin/unzip" directory:destPath withArgs:arguments input:nil]; - success = ([task result] == 0); + NSTask *task = [[NSTask alloc] init]; + task.launchPath = @"/usr/bin/unzip"; + task.currentDirectoryPath = destPath; + task.arguments = @[zipPath]; + + [task launch]; + [task waitUntilExit]; + success = (task.terminationStatus == 0); } @catch (NSException *exception) { @@ -143,9 +146,9 @@ { // ad-hoc signing with the dash NSArray *arguments = @[ @"--force", @"--deep", @"--sign", @"-", appPath ]; - NTSynchronousTask *task = [[NTSynchronousTask alloc] init]; - [task run:@"/usr/bin/codesign" directory:nil withArgs:arguments input:nil]; - success = ([task result] == 0); + NSTask *task = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/codesign" arguments:arguments]; + [task waitUntilExit]; + success = (task.terminationStatus == 0); } @catch (NSException *exception) { diff --git a/Vendor/CocoatechCore/NTSynchronousTask.h b/Vendor/CocoatechCore/NTSynchronousTask.h deleted file mode 100644 index cbcbf2c8..00000000 --- a/Vendor/CocoatechCore/NTSynchronousTask.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// NTSynchronousTask.h -// CocoatechCore -// -// Created by Steve Gehrman on 9/29/05. -// Copyright 2005 Steve Gehrman. All rights reserved. -// - -#ifndef NTSYNCHRONOUSTASK_H -#define NTSYNCHRONOUSTASK_H - -@interface NTSynchronousTask : NSObject -@property (readonly, strong) NSData *output; -@property (readonly) int result; - -// pass nil for directory if not needed -// returns the result -+(int) task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input output: (NSData**)outData; - -+(NSData*)task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input; - -- (void)run:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input; - -@end - -#endif diff --git a/Vendor/CocoatechCore/NTSynchronousTask.m b/Vendor/CocoatechCore/NTSynchronousTask.m deleted file mode 100644 index 3f583d7d..00000000 --- a/Vendor/CocoatechCore/NTSynchronousTask.m +++ /dev/null @@ -1,169 +0,0 @@ -// -// NTSynchronousTask.m -// CocoatechCore -// -// Created by Steve Gehrman on 9/29/05. -// Copyright 2005 Steve Gehrman. All rights reserved. -// - -#import "NTSynchronousTask.h" - -@interface NTSynchronousTask () -@property (strong) NSTask *task; -@property (strong) NSPipe *outputPipe; -@property (strong) NSPipe *inputPipe; -@property (readwrite, strong) NSData *output; -@property (getter = isDone) BOOL done; -@property (readwrite) int result; -@end - -@implementation NTSynchronousTask -@synthesize output = mv_output; -@synthesize result = mv_result; -@synthesize task = mv_task; -@synthesize outputPipe = mv_outputPipe; -@synthesize inputPipe = mv_inputPipe; -@synthesize done = mv_done; - -- (void)taskOutputAvailable:(NSNotification*)note -{ - self.output = [[note userInfo] objectForKey:NSFileHandleNotificationDataItem]; - - self.done = YES; -} - -- (void)taskDidTerminate:(NSNotification *) __unused note -{ - self.result = [self.task terminationStatus]; -} - -- (instancetype)init -{ - self = [super init]; - if (self) - { - self.task = [[NSTask alloc] init]; - self.outputPipe = [[NSPipe alloc] init]; - self.inputPipe = [[NSPipe alloc] init]; - - self.task.standardInput = self.inputPipe; - self.task.standardOutput = self.outputPipe; - self.task.standardError = self.outputPipe; - } - - return self; -} - -//---------------------------------------------------------- -// dealloc -//---------------------------------------------------------- -- (void)dealloc -{ - [[NSNotificationCenter defaultCenter] removeObserver:self]; -} - -- (void)run:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input -{ - BOOL success = NO; - - if (currentDirectory) { - self.task.currentDirectoryPath = currentDirectory; - } - - self.task.launchPath = toolPath; - self.task.arguments = args; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(taskOutputAvailable:) - name:NSFileHandleReadToEndOfFileCompletionNotification - object:[[self outputPipe] fileHandleForReading]]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(taskDidTerminate:) - name:NSTaskDidTerminateNotification - object:[self task]]; - - [[[self outputPipe] fileHandleForReading] readToEndOfFileInBackgroundAndNotifyForModes:@[NSDefaultRunLoopMode, NSModalPanelRunLoopMode, NSEventTrackingRunLoopMode]]; - - @try - { - [self.task launch]; - success = YES; - } - @catch (NSException *) { } - - if (success) - { - if (input) - { - // feed the running task our input - [[self.inputPipe fileHandleForWriting] writeData:input]; - [[self.inputPipe fileHandleForWriting] closeFile]; - } - - // loop until we are done receiving the data - if (!self.done) - { - double resolution = 1; - BOOL isRunning; - NSDate* next; - - do { - next = [NSDate dateWithTimeIntervalSinceNow:resolution]; - - isRunning = [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode - beforeDate:next]; - } while (isRunning && !self.done); - } - } -} - -+ (NSData*)task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input -{ - @autoreleasepool { - NSData* result = nil; - // we need this wacky pool here, otherwise we run out of pipes, the pipes are internally autoreleased - @try { - NTSynchronousTask* task = [[NTSynchronousTask alloc] init]; - - [task run:toolPath directory:currentDirectory withArgs:args input:input]; - - if ([task result] == 0) { - result = [task output]; - } - } - @catch (NSException *) { } - - return result; - } -} - - -+(int) task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input output: (NSData*__autoreleasing *)outData -{ - // we need this wacky pool here, otherwise we run out of pipes, the pipes are internally autoreleased - @autoreleasepool { - int taskResult = 0; - if (outData) { - *outData = nil; - } - - @try { - NTSynchronousTask* task = [[NTSynchronousTask alloc] init]; - - [task run:toolPath directory:currentDirectory withArgs:args input:input]; - - taskResult = [task result]; - if (outData) { - *outData = [task output]; - } - - } @catch (NSException *) { - taskResult = errCppGeneral; - } - - return taskResult; - } -} - -@end