mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-22 04:30:47 +00:00
Unarchive disk images using diskutil (#2930)
This change adopts using diskutil for dmg extraction on macOS 27.2+ where hdiutil has been deprecated.
This commit is contained in:
8 files changed
+174
-51
No files matched your search
@@ -247,8 +247,15 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
[_communicator handleMessageWithIdentifier:SPUExtractionStarted data:[NSData data]];
|
||||
|
||||
NSString *archivePath = [_updateDirectoryPath stringByAppendingPathComponent:_downloadName];
|
||||
|
||||
id<SUUnarchiverProtocol> unarchiver = [SUUnarchiver unarchiverForPath:archivePath extractionDirectory:_extractionDirectory updatingHostBundlePath:_host.bundlePath decryptionPassword:_decryptionPassword expectingInstallationType:_installationType];
|
||||
|
||||
NSString *extractionMountDirectory;
|
||||
if ([SUUnarchiver canUseExtractionMountDirectory:archivePath]) {
|
||||
extractionMountDirectory = [SPULocalCacheDirectory createUniqueDirectoryInDirectory:_updateDirectoryPath];
|
||||
} else {
|
||||
extractionMountDirectory = nil;
|
||||
}
|
||||
|
||||
id<SUUnarchiverProtocol> unarchiver = [SUUnarchiver unarchiverForPath:archivePath extractionDirectory:_extractionDirectory extractionMountDirectory:extractionMountDirectory updatingHostBundlePath:_host.bundlePath decryptionPassword:_decryptionPassword expectingInstallationType:_installationType];
|
||||
|
||||
NSError *prevalidationError = nil;
|
||||
BOOL success = NO;
|
||||
|
||||
@@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUDiskImageUnarchiver : NSObject <SUUnarchiverProtocol>
|
||||
|
||||
- (instancetype)initWithArchivePath:(NSString *)archivePath extractionDirectory:(NSString *)extractionDirectory decryptionPassword:(nullable NSString *)decryptionPassword;
|
||||
- (instancetype)initWithArchivePath:(NSString *)archivePath extractionDirectory:(NSString *)extractionDirectory extractionMountDirectory:(nullable NSString *)extractionMountDirectory decryptionPassword:(nullable NSString *)decryptionPassword;
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path;
|
||||
|
||||
|
||||
@@ -22,8 +22,10 @@
|
||||
NSString *_archivePath;
|
||||
NSString *_decryptionPassword;
|
||||
NSString *_extractionDirectory;
|
||||
NSString *_extractionMountDirectory;
|
||||
|
||||
SUUnarchiverNotifier *_notifier;
|
||||
|
||||
double _currentExtractionProgress;
|
||||
double _fileProgressIncrement;
|
||||
}
|
||||
@@ -38,13 +40,14 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (instancetype)initWithArchivePath:(NSString *)archivePath extractionDirectory:(NSString *)extractionDirectory decryptionPassword:(nullable NSString *)decryptionPassword
|
||||
- (instancetype)initWithArchivePath:(NSString *)archivePath extractionDirectory:(NSString *)extractionDirectory extractionMountDirectory:(nullable NSString *)extractionMountDirectory decryptionPassword:(nullable NSString *)decryptionPassword
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_archivePath = [archivePath copy];
|
||||
_decryptionPassword = [decryptionPassword copy];
|
||||
_extractionDirectory = [extractionDirectory copy];
|
||||
_extractionMountDirectory = [extractionMountDirectory copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -86,18 +89,30 @@ static NSUInteger fileCountForDirectory(NSFileManager *fileManager, NSString *it
|
||||
{
|
||||
@autoreleasepool {
|
||||
BOOL mountedSuccessfully = NO;
|
||||
|
||||
// Only use modern diskutil extraction over hdiutil if extraction mount directory has been specified
|
||||
BOOL useModernDiskUtilImplementation = (_extractionMountDirectory != nil);
|
||||
|
||||
// get a unique mount point path
|
||||
NSString *mountPoint = nil;
|
||||
NSFileManager *manager;
|
||||
NSString *mountPoint;
|
||||
NSError *error = nil;
|
||||
NSArray *contents = nil;
|
||||
do {
|
||||
NSString *uuidString = [[NSUUID UUID] UUIDString];
|
||||
mountPoint = [@"/Volumes" stringByAppendingPathComponent:uuidString];
|
||||
if (useModernDiskUtilImplementation) {
|
||||
mountPoint = _extractionMountDirectory;
|
||||
} else {
|
||||
do {
|
||||
NSString *uuidString = [[NSUUID UUID] UUIDString];
|
||||
mountPoint = [@"/Volumes" stringByAppendingPathComponent:uuidString];
|
||||
}
|
||||
// Note: this check does not follow symbolic links, which is what we want
|
||||
while ([[NSURL fileURLWithPath:mountPoint] checkResourceIsReachableAndReturnError:NULL]);
|
||||
}
|
||||
|
||||
if (mountPoint == nil) {
|
||||
error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey:@"Extraction failed because mountPoint failed to be created"}];
|
||||
|
||||
[notifier notifyFailureWithError:error];
|
||||
return;
|
||||
}
|
||||
// Note: this check does not follow symbolic links, which is what we want
|
||||
while ([[NSURL fileURLWithPath:mountPoint] checkResourceIsReachableAndReturnError:NULL]);
|
||||
|
||||
NSMutableData *inputData = [NSMutableData data];
|
||||
|
||||
@@ -110,22 +125,34 @@ static NSUInteger fileCountForDirectory(NSFileManager *fileManager, NSString *it
|
||||
[inputData appendData:decryptionPasswordData];
|
||||
}
|
||||
|
||||
// From the hdiutil docs:
|
||||
// read a null-terminated passphrase from standard input
|
||||
//
|
||||
// Add the null terminator
|
||||
[inputData appendBytes:"\0" length:1];
|
||||
|
||||
if (useModernDiskUtilImplementation) {
|
||||
// Unlike hdiutil, diskutil's --stdinpassphrase expects the passphrase to be
|
||||
// newline-terminated rather than null-terminated
|
||||
[inputData appendBytes:"\n" length:1];
|
||||
} else {
|
||||
// From the hdiutil docs:
|
||||
// read a null-terminated passphrase from standard input
|
||||
//
|
||||
// Add the null terminator
|
||||
[inputData appendBytes:"\0" length:1];
|
||||
}
|
||||
|
||||
// Append prompt data for license agreements
|
||||
[inputData appendBytes:"yes\n" length:4];
|
||||
}
|
||||
|
||||
// Finder doesn't verify disk images anymore beyond the code signing signature (if available)
|
||||
// Opt out of the old CRC checksum checks
|
||||
// Also always pass -stdinpass so we gracefully handle password protected disk images even if we aren't expecting them
|
||||
NSArray *arguments = @[@"attach", _archivePath, @"-mountpoint", mountPoint, @"-noverify", @"-nobrowse", @"-noautoopen", @"-stdinpass"];
|
||||
// Always pass -stdinpass / --stdinpassphrase so we gracefully handle password protected disk images even if we aren't expecting them
|
||||
NSArray<NSString *> *arguments;
|
||||
if (useModernDiskUtilImplementation) {
|
||||
arguments = @[@"image", @"attach", _archivePath, @"--mountPoint", mountPoint, @"--nobrowse", @"--stdinpassphrase"];
|
||||
} else {
|
||||
// Finder doesn't verify disk images anymore beyond the code signing signature (if available)
|
||||
// Opt out of the old CRC checksum checks
|
||||
arguments = @[@"attach", _archivePath, @"-mountpoint", mountPoint, @"-noverify", @"-nobrowse", @"-noautoopen", @"-stdinpass"];
|
||||
}
|
||||
|
||||
NSData *output = nil;
|
||||
NSData *errorOutput = nil;
|
||||
NSInteger taskResult = -1;
|
||||
|
||||
NSURL *mountPointURL = [NSURL fileURLWithPath:mountPoint isDirectory:YES];
|
||||
@@ -133,30 +160,61 @@ static NSUInteger fileCountForDirectory(NSFileManager *fileManager, NSString *it
|
||||
NSMutableArray<NSString *> *itemsToExtract = [NSMutableArray array];
|
||||
NSUInteger totalFileExtractionCount = 0;
|
||||
|
||||
NSFileManager *manager = nil;
|
||||
NSArray *contents = nil;
|
||||
|
||||
BOOL success = YES;
|
||||
|
||||
{
|
||||
NSTask *task = [[NSTask alloc] init];
|
||||
task.launchPath = @"/usr/bin/hdiutil";
|
||||
task.currentDirectoryPath = @"/";
|
||||
if (useModernDiskUtilImplementation) {
|
||||
task.executableURL = [NSURL fileURLWithPath:@"/usr/sbin/diskutil" isDirectory:NO];
|
||||
} else {
|
||||
task.executableURL = [NSURL fileURLWithPath:@"/usr/bin/hdiutil" isDirectory:NO];
|
||||
task.currentDirectoryPath = @"/";
|
||||
}
|
||||
|
||||
task.arguments = arguments;
|
||||
|
||||
NSPipe *inputPipe = [NSPipe pipe];
|
||||
NSPipe *outputPipe = [NSPipe pipe];
|
||||
NSPipe *errorPipe = [NSPipe pipe];
|
||||
|
||||
task.standardInput = inputPipe;
|
||||
task.standardOutput = outputPipe;
|
||||
task.standardError = errorPipe;
|
||||
|
||||
dispatch_queue_t captureQueue = dispatch_queue_create("org.sparkle-project.sparkle.dmg-output", DISPATCH_QUEUE_SERIAL);
|
||||
|
||||
NSFileHandle *fileStdHandle = outputPipe.fileHandleForReading;
|
||||
NSMutableData *currentOutput = [NSMutableData data];
|
||||
|
||||
fileStdHandle.readabilityHandler = ^(NSFileHandle *file) {
|
||||
[currentOutput appendData:file.availableData];
|
||||
NSData *availableData = file.availableData;
|
||||
|
||||
dispatch_sync(captureQueue, ^{
|
||||
[currentOutput appendData:availableData];
|
||||
});
|
||||
};
|
||||
|
||||
NSFileHandle *fileErrHandle = errorPipe.fileHandleForReading;
|
||||
NSMutableData *currentErrorOutput = [NSMutableData data];
|
||||
|
||||
fileErrHandle.readabilityHandler = ^(NSFileHandle *file) {
|
||||
NSData *availableData = file.availableData;
|
||||
|
||||
dispatch_sync(captureQueue, ^{
|
||||
[currentErrorOutput appendData:availableData];
|
||||
});
|
||||
};
|
||||
|
||||
__block NSData *capturedOutput = nil;
|
||||
__block NSData *capturedErrorOutput = nil;
|
||||
|
||||
dispatch_semaphore_t terminationSemaphore = dispatch_semaphore_create(0);
|
||||
task.terminationHandler = ^(NSTask *__unused terminatingTask) {
|
||||
fileStdHandle.readabilityHandler = nil;
|
||||
fileErrHandle.readabilityHandler = nil;
|
||||
|
||||
dispatch_semaphore_signal(terminationSemaphore);
|
||||
};
|
||||
@@ -172,16 +230,24 @@ static NSUInteger fileCountForDirectory(NSFileManager *fileManager, NSString *it
|
||||
[inputPipe.fileHandleForWriting closeFile];
|
||||
|
||||
dispatch_semaphore_wait(terminationSemaphore, DISPATCH_TIME_FOREVER);
|
||||
output = [currentOutput copy];
|
||||
|
||||
dispatch_sync(captureQueue, ^{
|
||||
capturedOutput = [currentOutput copy];
|
||||
capturedErrorOutput = [currentErrorOutput copy];
|
||||
});
|
||||
|
||||
output = capturedOutput;
|
||||
errorOutput = capturedErrorOutput;
|
||||
|
||||
taskResult = task.terminationStatus;
|
||||
}
|
||||
|
||||
if (taskResult != 0) {
|
||||
NSString *resultStr = output ? [[NSString alloc] initWithData:output encoding:NSUTF8StringEncoding] : nil;
|
||||
SULog(SULogLevelError, @"hdiutil failed with code: %ld data: <<%@>>", (long)taskResult, resultStr);
|
||||
NSString *errorStr = errorOutput ? [[NSString alloc] initWithData:errorOutput encoding:NSUTF8StringEncoding] : nil;
|
||||
SULog(SULogLevelError, @"%@ failed with code: %ld data: <<%@>> error: <<%@>>", (useModernDiskUtilImplementation ? @"diskutil" : @"hdiutil"), (long)taskResult, resultStr, errorStr);
|
||||
|
||||
error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Extraction failed due to hdiutil returning %ld status: %@", (long)taskResult, resultStr]}];
|
||||
error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Extraction failed due to %@ returning %ld status: %@", useModernDiskUtilImplementation ? @"diskutil" : @"hdiutil", (long)taskResult, resultStr]}];
|
||||
|
||||
goto reportError;
|
||||
}
|
||||
@@ -284,16 +350,24 @@ static NSUInteger fileCountForDirectory(NSFileManager *fileManager, NSString *it
|
||||
finally:
|
||||
if (mountedSuccessfully) {
|
||||
NSTask *task = [[NSTask alloc] init];
|
||||
task.launchPath = @"/usr/bin/hdiutil";
|
||||
task.arguments = @[@"detach", mountPoint, @"-force"];
|
||||
|
||||
if (useModernDiskUtilImplementation) {
|
||||
task.launchPath = @"/usr/sbin/diskutil";
|
||||
task.arguments = @[@"eject", @"force", mountPoint];
|
||||
} else {
|
||||
task.launchPath = @"/usr/bin/hdiutil";
|
||||
task.arguments = @[@"detach", mountPoint, @"-force"];
|
||||
}
|
||||
task.standardOutput = [NSPipe pipe];
|
||||
task.standardError = [NSPipe pipe];
|
||||
|
||||
NSError *launchCleanupError = nil;
|
||||
if (![task launchAndReturnError:&launchCleanupError]) {
|
||||
SULog(SULogLevelError, @"Failed to unmount %@", mountPoint);
|
||||
SULog(SULogLevelError, @"%@ failed to unmount %@", (useModernDiskUtilImplementation ? @"diskutil" : @"hdiutil"), mountPoint);
|
||||
SULog(SULogLevelError, @"Error: %@", launchCleanupError);
|
||||
} else if (waitForCleanup) {
|
||||
} else if (waitForCleanup || !success) {
|
||||
// On the failure path the caller may immediately remove the directory the mount point lives in,
|
||||
// so don't report failure until the volume is actually gone
|
||||
[task waitUntilExit];
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -14,7 +14,11 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUUnarchiver : NSObject
|
||||
|
||||
+ (nullable id <SUUnarchiverProtocol>)unarchiverForPath:(NSString *)path extractionDirectory:(NSString *)extractionDirectory updatingHostBundlePath:(nullable NSString *)hostPath decryptionPassword:(nullable NSString *)decryptionPassword expectingInstallationType:(NSString *)installationType;
|
||||
+ (nullable id <SUUnarchiverProtocol>)unarchiverForPath:(NSString *)path extractionDirectory:(NSString *)extractionDirectory extractionMountDirectory:(nullable NSString *)extractionMountDirectory updatingHostBundlePath:(nullable NSString *)hostPath decryptionPassword:(nullable NSString *)decryptionPassword expectingInstallationType:(NSString *)installationType;
|
||||
|
||||
// Returns YES if unarchiving path can take advantage of an extraction mount directory being provided to -unarchiverForPath:extractionDirectory:extractionMountDirectory:updatingHostBundlePath:decryptionPassword:expectingInstallationType:
|
||||
// Callers should provide an extraction mount directory when this returns YES
|
||||
+ (BOOL)canUseExtractionMountDirectory:(NSString *)path;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -18,13 +18,28 @@
|
||||
|
||||
@implementation SUUnarchiver
|
||||
|
||||
+ (nullable id <SUUnarchiverProtocol>)unarchiverForPath:(NSString *)path extractionDirectory:(NSString *)extractionDirectory updatingHostBundlePath:(nullable NSString *)hostPath decryptionPassword:(nullable NSString *)decryptionPassword expectingInstallationType:(NSString *)installationType
|
||||
+ (BOOL)canUseExtractionMountDirectory:(NSString *)path
|
||||
{
|
||||
if (![SUDiskImageUnarchiver canUnarchivePath:path]) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
// By providing a directory for mounting, this lets the disk image unarchiver use diskutil over hdiutil
|
||||
// diskutil extraction works well across all dmgs only on macOS 27.2+
|
||||
if (@available(macOS 27.2, *)) {
|
||||
return YES;
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
+ (nullable id <SUUnarchiverProtocol>)unarchiverForPath:(NSString *)path extractionDirectory:(NSString *)extractionDirectory extractionMountDirectory:(nullable NSString *)extractionMountDirectory updatingHostBundlePath:(nullable NSString *)hostPath decryptionPassword:(nullable NSString *)decryptionPassword expectingInstallationType:(NSString *)installationType
|
||||
{
|
||||
if ([SUPipedUnarchiver canUnarchivePath:path]) {
|
||||
return [[SUPipedUnarchiver alloc] initWithArchivePath:path extractionDirectory:extractionDirectory];
|
||||
}
|
||||
else if ([SUDiskImageUnarchiver canUnarchivePath:path]) {
|
||||
return [[SUDiskImageUnarchiver alloc] initWithArchivePath:path extractionDirectory:extractionDirectory decryptionPassword:decryptionPassword];
|
||||
return [[SUDiskImageUnarchiver alloc] initWithArchivePath:path extractionDirectory:extractionDirectory extractionMountDirectory:extractionMountDirectory decryptionPassword:decryptionPassword];
|
||||
}
|
||||
else if ([SUBinaryDeltaUnarchiver canUnarchivePath:path]) {
|
||||
assert(hostPath != nil);
|
||||
|
||||
@@ -14,6 +14,17 @@ class SUUnarchiverTest: XCTestCase
|
||||
let appName = resourceName
|
||||
let archiveResourceURL = Bundle(for: type(of: self)).url(forResource: appName, withExtension: archiveExtension)!
|
||||
|
||||
// When an extraction mount directory is supported, test both providing one and not providing one,
|
||||
// so that the disk image unarchiver's diskutil and hdiutil code paths are both exercised
|
||||
let extractionMountDirectoryOptions = SUUnarchiver.canUseExtractionMountDirectory(archiveResourceURL.path) ? [true, false] : [false]
|
||||
|
||||
for providingExtractionMountDirectory in extractionMountDirectoryOptions {
|
||||
self.unarchiveTestAppWithExtension(archiveExtension, archiveResourceURL: archiveResourceURL, password: password, providingExtractionMountDirectory: providingExtractionMountDirectory, expectingInstallationType: installationType, expectingSuccess: expectingSuccess, extractedAppName: extractedAppName)
|
||||
}
|
||||
}
|
||||
|
||||
// swiftlint:disable function_parameter_count
|
||||
func unarchiveTestAppWithExtension(_ archiveExtension: String, archiveResourceURL: URL, password: String?, providingExtractionMountDirectory: Bool, expectingInstallationType installationType: String, expectingSuccess: Bool, extractedAppName: String) {
|
||||
let fileManager = FileManager.default
|
||||
|
||||
// Do not remove this temporary directory
|
||||
@@ -21,11 +32,11 @@ class SUUnarchiverTest: XCTestCase
|
||||
// after *both* our unarchive success and failure calls below finish (they both have async completion blocks inside their implementation)
|
||||
let tempDirectoryURL = try! fileManager.url(for: .itemReplacementDirectory, in: .userDomainMask, appropriateFor: URL(fileURLWithPath: NSHomeDirectory()), create: true)
|
||||
|
||||
let unarchivedSuccessExpectation = super.expectation(description: "Unarchived Success (format: \(archiveExtension))")
|
||||
let unarchivedFailureExpectation = super.expectation(description: "Unarchived Failure (format: \(archiveExtension))")
|
||||
let unarchivedSuccessExpectation = super.expectation(description: "Unarchived Success (format: \(archiveExtension), mount directory: \(providingExtractionMountDirectory))")
|
||||
let unarchivedFailureExpectation = super.expectation(description: "Unarchived Failure (format: \(archiveExtension), mount directory: \(providingExtractionMountDirectory))")
|
||||
|
||||
self.unarchiveTestAppWithExtension(archiveExtension, appName: appName, tempDirectoryURL: tempDirectoryURL, archiveResourceURL: archiveResourceURL, password: password, expectingInstallationType: installationType, expectingSuccess: expectingSuccess, testExpectation: unarchivedSuccessExpectation)
|
||||
self.unarchiveNonExistentFileTestFailureAppWithExtension(archiveExtension, tempDirectoryURL: tempDirectoryURL, password: password, expectingInstallationType: installationType, testExpectation: unarchivedFailureExpectation)
|
||||
self.unarchiveTestAppWithExtension(archiveExtension, tempDirectoryURL: tempDirectoryURL, archiveResourceURL: archiveResourceURL, password: password, providingExtractionMountDirectory: providingExtractionMountDirectory, expectingInstallationType: installationType, expectingSuccess: expectingSuccess, testExpectation: unarchivedSuccessExpectation)
|
||||
self.unarchiveNonExistentFileTestFailureAppWithExtension(archiveExtension, tempDirectoryURL: tempDirectoryURL, password: password, providingExtractionMountDirectory: providingExtractionMountDirectory, expectingInstallationType: installationType, testExpectation: unarchivedFailureExpectation)
|
||||
|
||||
super.waitForExpectations(timeout: 30.0, handler: nil)
|
||||
|
||||
@@ -43,10 +54,13 @@ class SUUnarchiverTest: XCTestCase
|
||||
}
|
||||
}
|
||||
|
||||
func unarchiveNonExistentFileTestFailureAppWithExtension(_ archiveExtension: String, tempDirectoryURL: URL, password: String?, expectingInstallationType installationType: String, testExpectation: XCTestExpectation) {
|
||||
func unarchiveNonExistentFileTestFailureAppWithExtension(_ archiveExtension: String, tempDirectoryURL: URL, password: String?, providingExtractionMountDirectory: Bool, expectingInstallationType installationType: String, testExpectation: XCTestExpectation) {
|
||||
let tempArchiveURL = tempDirectoryURL.deletingLastPathComponent().appendingPathComponent("error-invalid").appendingPathExtension(archiveExtension)
|
||||
|
||||
let unarchiver = SUUnarchiver.unarchiver(forPath: tempArchiveURL.path, extractionDirectory: tempDirectoryURL.path, updatingHostBundlePath: nil, decryptionPassword: password, expectingInstallationType: installationType)!
|
||||
|
||||
// The disk image unarchiver will create and remove this directory automatically
|
||||
let extractionMountDirectory: String? = providingExtractionMountDirectory ? URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true).appendingPathComponent(ProcessInfo.processInfo.globallyUniqueString).path : nil
|
||||
|
||||
let unarchiver = SUUnarchiver.unarchiver(forPath: tempArchiveURL.path, extractionDirectory: tempDirectoryURL.path, extractionMountDirectory: extractionMountDirectory, updatingHostBundlePath: nil, decryptionPassword: password, expectingInstallationType: installationType)!
|
||||
|
||||
unarchiver.unarchive(completionBlock: {(error: Error?) -> Void in
|
||||
XCTAssertNotNil(error)
|
||||
@@ -54,10 +68,12 @@ class SUUnarchiverTest: XCTestCase
|
||||
}, progressBlock: nil, waitForCleanup: true)
|
||||
}
|
||||
|
||||
// swiftlint:disable function_parameter_count
|
||||
func unarchiveTestAppWithExtension(_ archiveExtension: String, appName: String, tempDirectoryURL: URL, archiveResourceURL: URL, password: String?, expectingInstallationType installationType: String, expectingSuccess: Bool, testExpectation: XCTestExpectation) {
|
||||
|
||||
let unarchiver = SUUnarchiver.unarchiver(forPath: archiveResourceURL.path, extractionDirectory: tempDirectoryURL.path, updatingHostBundlePath: nil, decryptionPassword: password, expectingInstallationType: installationType)!
|
||||
func unarchiveTestAppWithExtension(_ archiveExtension: String, tempDirectoryURL: URL, archiveResourceURL: URL, password: String?, providingExtractionMountDirectory: Bool, expectingInstallationType installationType: String, expectingSuccess: Bool, testExpectation: XCTestExpectation) {
|
||||
|
||||
// The disk image unarchiver will create and remove this directory automatically
|
||||
let extractionMountDirectory: String? = providingExtractionMountDirectory ? URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true).appendingPathComponent(ProcessInfo.processInfo.globallyUniqueString).path : nil
|
||||
|
||||
let unarchiver = SUUnarchiver.unarchiver(forPath: archiveResourceURL.path, extractionDirectory: tempDirectoryURL.path, extractionMountDirectory: extractionMountDirectory, updatingHostBundlePath: nil, decryptionPassword: password, expectingInstallationType: installationType)!
|
||||
|
||||
unarchiver.unarchive(completionBlock: {(error: Error?) -> Void in
|
||||
if expectingSuccess {
|
||||
|
||||
@@ -7,12 +7,15 @@ import Foundation
|
||||
|
||||
func unarchive(itemPath: URL, archiveDestDir: URL, callback: @escaping (Error?) -> Void) {
|
||||
let fileManager = FileManager.default
|
||||
let tempDir = archiveDestDir.appendingPathExtension("tmp")
|
||||
let tempExtractionDir = archiveDestDir.appendingPathExtension("tmp")
|
||||
|
||||
_ = try? fileManager.removeItem(at: tempDir)
|
||||
_ = try? fileManager.createDirectory(at: tempDir, withIntermediateDirectories: true, attributes: [:])
|
||||
_ = try? fileManager.removeItem(at: tempExtractionDir)
|
||||
_ = try? fileManager.createDirectory(at: tempExtractionDir, withIntermediateDirectories: true, attributes: [:])
|
||||
|
||||
// The disk image unarchiver will create and remove this directory automatically
|
||||
let extractionMountDirectory: String? = SUUnarchiver.canUseExtractionMountDirectory(itemPath.path) ? URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true).appendingPathComponent(ProcessInfo.processInfo.globallyUniqueString).path : nil
|
||||
|
||||
if let unarchiver = SUUnarchiver.unarchiver(forPath: itemPath.path, extractionDirectory: tempDir.path, updatingHostBundlePath: nil, decryptionPassword: nil, expectingInstallationType: SPUInstallationTypeApplication) {
|
||||
if let unarchiver = SUUnarchiver.unarchiver(forPath: itemPath.path, extractionDirectory: tempExtractionDir.path, extractionMountDirectory: extractionMountDirectory, updatingHostBundlePath: nil, decryptionPassword: nil, expectingInstallationType: SPUInstallationTypeApplication) {
|
||||
unarchiver.unarchive(completionBlock: { (error: Error?) in
|
||||
if error != nil {
|
||||
callback(error)
|
||||
@@ -20,7 +23,7 @@ func unarchive(itemPath: URL, archiveDestDir: URL, callback: @escaping (Error?)
|
||||
}
|
||||
|
||||
do {
|
||||
try fileManager.moveItem(at: tempDir, to: archiveDestDir)
|
||||
try fileManager.moveItem(at: tempExtractionDir, to: archiveDestDir)
|
||||
callback(nil)
|
||||
} catch {
|
||||
callback(error)
|
||||
|
||||
@@ -259,6 +259,10 @@ struct GenerateAppcast: ParsableCommand {
|
||||
// terminate the process, when extracting archives
|
||||
signal(SIGPIPE, SIG_IGN)
|
||||
|
||||
// This satisfies unarchiving disk images in interactive sessions without diskutil (macOS 27.2+)
|
||||
// making it require the user to enter a response for images that have license agreements
|
||||
setenv("PAGER", "true", 1)
|
||||
|
||||
// Extract the keys
|
||||
let privateDSAKey : SecKey?
|
||||
#if GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT
|
||||
|
||||
Reference in new issue
Block a user