diff --git a/Sparkle/SUPipedUnarchiver.m b/Sparkle/SUPipedUnarchiver.m index 1849b85f..75493679 100644 --- a/Sparkle/SUPipedUnarchiver.m +++ b/Sparkle/SUPipedUnarchiver.m @@ -105,43 +105,49 @@ NSFileHandle *archiveInput = [NSFileHandle fileHandleForReadingAtPath:self.archivePath]; NSPipe *pipe = [NSPipe pipe]; - NSFileHandle *archiveOutput = [pipe fileHandleForWriting]; - NSTask *task = [[NSTask alloc] init]; [task setStandardInput:[pipe fileHandleForReading]]; [task setStandardError:[NSFileHandle fileHandleWithStandardError]]; [task setStandardOutput:[NSFileHandle fileHandleWithStandardOutput]]; [task setLaunchPath:command]; [task setArguments:[args arrayByAddingObject:destination]]; - [task launch]; - - NSUInteger bytesRead = 0; - do { - NSData *data = [archiveInput readDataOfLength:256*1024]; - NSUInteger len = [data length]; - if (!len) { - break; - } - bytesRead += len; - [archiveOutput writeData:data]; - [notifier notifyProgress:(double)bytesRead / (double)expectedLength]; + @try { + [task launch]; + } + @catch (NSException *e) { + error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Extraction failed, -[NSTask launch] threw exception '%@'", e.description]}]; } - while(bytesRead < expectedLength); - [archiveOutput closeFile]; - - [task waitUntilExit]; - - if ([task terminationStatus] == 0) { - if (bytesRead == expectedLength) { - [notifier notifySuccess]; - return; - } else { - error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Extraction failed, command '%@' got only %ld of %ld bytes", command, (long)bytesRead, (long)expectedLength]}]; - + if (!error) { + NSFileHandle *archiveOutput = [pipe fileHandleForWriting]; + NSUInteger bytesRead = 0; + do { + NSData *data = [archiveInput readDataOfLength:256*1024]; + NSUInteger len = [data length]; + if (!len) { + break; + } + bytesRead += len; + [archiveOutput writeData:data]; + [notifier notifyProgress:(double)bytesRead / (double)expectedLength]; + } + while(bytesRead < expectedLength); + + [archiveOutput closeFile]; + + [task waitUntilExit]; + + if ([task terminationStatus] == 0) { + if (bytesRead == expectedLength) { + [notifier notifySuccess]; + return; + } else { + error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Extraction failed, command '%@' got only %ld of %ld bytes", command, (long)bytesRead, (long)expectedLength]}]; + + } + } else { + error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Extraction failed, command '%@' returned %d", command, [task terminationStatus]]}]; } - } else { - error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Extraction failed, command '%@' returned %d", command, [task terminationStatus]]}]; } } else { error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Extraction failed, archive '%@' is empty", self.archivePath]}];