Compare commits

...
6 Commits
Author SHA1 Message Date
Zorg 0066846648 Don't clean up update directory when Autoupdate receives SIGTERM
Under rare circumstances, if Autoupdate receives SIGTERM while the installer queue is installing an update this could cause potential corruption.

This is a port of #2479 to 2.2.x branch.
2024-05-12 17:17:43 -07:00
Zorg 47fb37e55d Merge branch 'extraction-update-2.2.x' into 2.2.x 2024-05-12 17:15:59 -07:00
Zorg c0bb61cc8f Revert unarchiver code to how it used to work in generate_appcast 2024-05-12 17:15:28 -07:00
Zorg 80c8c1ff3d Extract archives in a separate directory from the input archive (2.2.x) (#2553) 2024-05-05 21:49:56 -07:00
Zorg 464e269922 Change CI branch to 2.2.x 2024-05-02 23:15:29 +02:00
Zorg bb1e4d0907 Extract archives in a separate directory from the input archive
This is ported from top of 2.x.
2024-05-02 16:13:23 +02:00
16 changed files with 114 additions and 77 deletions

No files matched your search

+2 -2
View File
@@ -2,9 +2,9 @@ name: Build & Tests
on: on:
push: push:
branches: [ 2.x, 2.2.2-dev, master ] branches: [ 2.x, 2.2.x, master ]
pull_request: pull_request:
branches: [ 2.x, 2.2.2-dev, master ] branches: [ 2.x, 2.2.x, master ]
jobs: jobs:
build: build:
+14 -3
View File
@@ -59,6 +59,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
@property (nonatomic, readonly) NSString *userName; @property (nonatomic, readonly) NSString *userName;
@property (nonatomic) SUHost *host; @property (nonatomic) SUHost *host;
@property (nonatomic, copy) NSString *updateDirectoryPath; @property (nonatomic, copy) NSString *updateDirectoryPath;
@property (nonatomic, copy) NSString *extractionDirectory;
@property (nonatomic, copy) NSString *downloadName; @property (nonatomic, copy) NSString *downloadName;
@property (nonatomic, copy) NSString *decryptionPassword; @property (nonatomic, copy) NSString *decryptionPassword;
@property (nonatomic, strong) SUSignatures *signatures; @property (nonatomic, strong) SUSignatures *signatures;
@@ -94,6 +95,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
@synthesize updateValidator = _updateValidator; @synthesize updateValidator = _updateValidator;
@synthesize host = _host; @synthesize host = _host;
@synthesize updateDirectoryPath = _updateDirectoryPath; @synthesize updateDirectoryPath = _updateDirectoryPath;
@synthesize extractionDirectory = _extractionDirectory;
@synthesize downloadName = _downloadName; @synthesize downloadName = _downloadName;
@synthesize decryptionPassword = _decryptionPassword; @synthesize decryptionPassword = _decryptionPassword;
@synthesize signatures = _signatures; @synthesize signatures = _signatures;
@@ -193,7 +195,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
[self.communicator handleMessageWithIdentifier:SPUExtractionStarted data:[NSData data]]; [self.communicator handleMessageWithIdentifier:SPUExtractionStarted data:[NSData data]];
NSString *archivePath = [self.updateDirectoryPath stringByAppendingPathComponent:self.downloadName]; NSString *archivePath = [self.updateDirectoryPath stringByAppendingPathComponent:self.downloadName];
id<SUUnarchiverProtocol> unarchiver = [SUUnarchiver unarchiverForPath:archivePath updatingHostBundlePath:self.host.bundlePath decryptionPassword:self.decryptionPassword expectingInstallationType:self.installationType]; id<SUUnarchiverProtocol> unarchiver = [SUUnarchiver unarchiverForPath:archivePath extractionDirectory:self.extractionDirectory updatingHostBundlePath:self.host.bundlePath decryptionPassword:self.decryptionPassword expectingInstallationType:self.installationType];
NSError *unarchiverError = nil; NSError *unarchiverError = nil;
BOOL success = NO; BOOL success = NO;
@@ -226,7 +228,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
[self.communicator handleMessageWithIdentifier:SPUValidationStarted data:[NSData data]]; [self.communicator handleMessageWithIdentifier:SPUValidationStarted data:[NSData data]];
NSError *validationError = nil; NSError *validationError = nil;
BOOL validationSuccess = [self.updateValidator validateWithUpdateDirectory:self.updateDirectoryPath error:&validationError]; BOOL validationSuccess = [self.updateValidator validateWithUpdateDirectory:self.extractionDirectory error:&validationError];
if (!validationSuccess) { if (!validationSuccess) {
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Update validation was a failure", NSUnderlyingErrorKey: validationError }]]; [self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Update validation was a failure", NSUnderlyingErrorKey: validationError }]];
@@ -276,6 +278,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
// but may as well set other fields to nil too // but may as well set other fields to nil too
[self clearUpdateDirectory]; [self clearUpdateDirectory];
self.downloadName = nil; self.downloadName = nil;
self.extractionDirectory = nil;
self.decryptionPassword = nil; self.decryptionPassword = nil;
self.signatures = nil; self.signatures = nil;
self.relaunchPath = nil; self.relaunchPath = nil;
@@ -407,6 +410,13 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
return; return;
} }
NSString *extractionDirectory = [SPULocalCacheDirectory createUniqueDirectoryInDirectory:cacheInstallationPath];
if (extractionDirectory == nil) {
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Error: Failed to create installation extraction directory in %@", cacheInstallationPath] }]];
return;
}
// Carry these properities separately rather than using the SUInstallationInputData object // Carry these properities separately rather than using the SUInstallationInputData object
// Some of our properties may slightly differ than our input and we don't want to make the mistake of using one of those // Some of our properties may slightly differ than our input and we don't want to make the mistake of using one of those
self.installationType = installationType; self.installationType = installationType;
@@ -414,6 +424,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
self.downloadName = installationData.downloadName; self.downloadName = installationData.downloadName;
self.signatures = installationData.signatures; self.signatures = installationData.signatures;
self.updateDirectoryPath = cacheInstallationPath; self.updateDirectoryPath = cacheInstallationPath;
self.extractionDirectory = extractionDirectory;
self.host = [[SUHost alloc] initWithBundle:hostBundle]; self.host = [[SUHost alloc] initWithBundle:hostBundle];
[self extractAndInstallUpdate]; [self extractAndInstallUpdate];
@@ -463,7 +474,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
dispatch_async(self.installerQueue, ^{ dispatch_async(self.installerQueue, ^{
NSError *installerError = nil; NSError *installerError = nil;
id <SUInstallerProtocol> installer = [SUInstaller installerForHost:self.host expectedInstallationType:self.installationType updateDirectory:self.updateDirectoryPath homeDirectory:self.homeDirectory userName:self.userName error:&installerError]; id <SUInstallerProtocol> installer = [SUInstaller installerForHost:self.host expectedInstallationType:self.installationType updateDirectory:self.extractionDirectory homeDirectory:self.homeDirectory userName:self.userName error:&installerError];
if (installer == nil) { if (installer == nil) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
+1 -1
View File
@@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface SUBinaryDeltaUnarchiver : NSObject <SUUnarchiverProtocol> @interface SUBinaryDeltaUnarchiver : NSObject <SUUnarchiverProtocol>
- (instancetype)initWithArchivePath:(NSString *)archivePath updateHostBundlePath:(NSString *)updateHostBundlePath; - (instancetype)initWithArchivePath:(NSString *)archivePath extractionDirectory:(NSString *)extractionDirectory updateHostBundlePath:(NSString *)updateHostBundlePath;
@end @end
+5 -2
View File
@@ -20,6 +20,7 @@
@property (nonatomic, copy, readonly) NSString *archivePath; @property (nonatomic, copy, readonly) NSString *archivePath;
@property (nonatomic, copy, readonly) NSString *updateHostBundlePath; @property (nonatomic, copy, readonly) NSString *updateHostBundlePath;
@property (nonatomic, copy, readonly) NSString *extractionDirectory;
@end @end
@@ -27,6 +28,7 @@
@synthesize archivePath = _archivePath; @synthesize archivePath = _archivePath;
@synthesize updateHostBundlePath = _updateHostBundlePath; @synthesize updateHostBundlePath = _updateHostBundlePath;
@synthesize extractionDirectory = _extractionDirectory;
+ (BOOL)canUnarchivePath:(NSString *)path + (BOOL)canUnarchivePath:(NSString *)path
{ {
@@ -73,12 +75,13 @@
} }
} }
- (instancetype)initWithArchivePath:(NSString *)archivePath updateHostBundlePath:(NSString *)updateHostBundlePath - (instancetype)initWithArchivePath:(NSString *)archivePath extractionDirectory:(NSString *)extractionDirectory updateHostBundlePath:(NSString *)updateHostBundlePath
{ {
self = [super init]; self = [super init];
if (self != nil) { if (self != nil) {
_archivePath = [archivePath copy]; _archivePath = [archivePath copy];
_updateHostBundlePath = [updateHostBundlePath copy]; _updateHostBundlePath = [updateHostBundlePath copy];
_extractionDirectory = [extractionDirectory copy];
} }
return self; return self;
} }
@@ -96,7 +99,7 @@
- (void)extractDeltaWithNotifier:(SUUnarchiverNotifier *)notifier - (void)extractDeltaWithNotifier:(SUUnarchiverNotifier *)notifier
{ {
NSString *sourcePath = self.updateHostBundlePath; NSString *sourcePath = self.updateHostBundlePath;
NSString *targetPath = [[self.archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:[sourcePath lastPathComponent]]; NSString *targetPath = [self.extractionDirectory stringByAppendingPathComponent:[sourcePath lastPathComponent]];
NSError *applyDiffError = nil; NSError *applyDiffError = nil;
BOOL success = applyBinaryDelta(sourcePath, targetPath, self.archivePath, NO, ^(double progress){ BOOL success = applyBinaryDelta(sourcePath, targetPath, self.archivePath, NO, ^(double progress){
+1 -1
View File
@@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface SUDiskImageUnarchiver : NSObject <SUUnarchiverProtocol> @interface SUDiskImageUnarchiver : NSObject <SUUnarchiverProtocol>
- (instancetype)initWithArchivePath:(NSString *)archivePath decryptionPassword:(nullable NSString *)decryptionPassword; - (instancetype)initWithArchivePath:(NSString *)archivePath extractionDirectory:(NSString *)extractionDirectory decryptionPassword:(nullable NSString *)decryptionPassword;
@end @end
+5 -2
View File
@@ -17,6 +17,7 @@
@property (nonatomic, copy, readonly) NSString *archivePath; @property (nonatomic, copy, readonly) NSString *archivePath;
@property (nullable, nonatomic, copy, readonly) NSString *decryptionPassword; @property (nullable, nonatomic, copy, readonly) NSString *decryptionPassword;
@property (nonatomic, copy, readonly) NSString *extractionDirectory;
@end @end
@@ -24,6 +25,7 @@
@synthesize archivePath = _archivePath; @synthesize archivePath = _archivePath;
@synthesize decryptionPassword = _decryptionPassword; @synthesize decryptionPassword = _decryptionPassword;
@synthesize extractionDirectory = _extractionDirectory;
+ (BOOL)canUnarchivePath:(NSString *)path + (BOOL)canUnarchivePath:(NSString *)path
{ {
@@ -35,12 +37,13 @@
return NO; return NO;
} }
- (instancetype)initWithArchivePath:(NSString *)archivePath decryptionPassword:(nullable NSString *)decryptionPassword - (instancetype)initWithArchivePath:(NSString *)archivePath extractionDirectory:(NSString *)extractionDirectory decryptionPassword:(nullable NSString *)decryptionPassword
{ {
self = [super init]; self = [super init];
if (self != nil) { if (self != nil) {
_archivePath = [archivePath copy]; _archivePath = [archivePath copy];
_decryptionPassword = [decryptionPassword copy]; _decryptionPassword = [decryptionPassword copy];
_extractionDirectory = [extractionDirectory copy];
} }
return self; return self;
} }
@@ -189,7 +192,7 @@
for (NSString *item in contents) for (NSString *item in contents)
{ {
NSString *fromPath = [mountPoint stringByAppendingPathComponent:item]; NSString *fromPath = [mountPoint stringByAppendingPathComponent:item];
NSString *toPath = [[self.archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:item]; NSString *toPath = [self.extractionDirectory stringByAppendingPathComponent:item];
itemsCopied += 1.0; itemsCopied += 1.0;
[notifier notifyProgress:0.5 + itemsCopied/(totalItems*2.0)]; [notifier notifyProgress:0.5 + itemsCopied/(totalItems*2.0)];
+1 -1
View File
@@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
// An unarchiver for flat packages that doesn't really do any unarchiving // An unarchiver for flat packages that doesn't really do any unarchiving
@interface SUFlatPackageUnarchiver : NSObject <SUUnarchiverProtocol> @interface SUFlatPackageUnarchiver : NSObject <SUUnarchiverProtocol>
- (instancetype)initWithFlatPackagePath:(NSString *)flatPackagePath expectingInstallationType:(NSString *)installationType; - (instancetype)initWithFlatPackagePath:(NSString *)flatPackagePath extractionDirectory:(NSString *)extractionDirectory expectingInstallationType:(NSString *)installationType;
@end @end
+18 -3
View File
@@ -18,6 +18,7 @@
@property (nonatomic, readonly) NSString *flatPackagePath; @property (nonatomic, readonly) NSString *flatPackagePath;
@property (nonatomic, readonly) NSString *expectedInstallationType; @property (nonatomic, readonly) NSString *expectedInstallationType;
@property (nonatomic, readonly) NSString *extractionDirectory;
@end @end
@@ -25,6 +26,7 @@
@synthesize flatPackagePath = _flatPackagePath; @synthesize flatPackagePath = _flatPackagePath;
@synthesize expectedInstallationType = _expectedInstallationType; @synthesize expectedInstallationType = _expectedInstallationType;
@synthesize extractionDirectory = _extractionDirectory;
+ (BOOL)canUnarchivePath:(NSString *)path + (BOOL)canUnarchivePath:(NSString *)path
{ {
@@ -36,12 +38,13 @@
return YES; return YES;
} }
- (instancetype)initWithFlatPackagePath:(NSString *)flatPackagePath expectingInstallationType:(NSString *)installationType - (instancetype)initWithFlatPackagePath:(NSString *)flatPackagePath extractionDirectory:(NSString *)extractionDirectory expectingInstallationType:(NSString *)installationType
{ {
self = [super init]; self = [super init];
if (self != nil) { if (self != nil) {
_flatPackagePath = [flatPackagePath copy]; _flatPackagePath = [flatPackagePath copy];
_expectedInstallationType = [installationType copy]; _expectedInstallationType = [installationType copy];
_extractionDirectory = [extractionDirectory copy];
} }
return self; return self;
} }
@@ -57,8 +60,20 @@
} else if (![[NSFileManager defaultManager] fileExistsAtPath:self.flatPackagePath isDirectory:&isDirectory] || isDirectory) { } else if (![[NSFileManager defaultManager] fileExistsAtPath:self.flatPackagePath isDirectory:&isDirectory] || isDirectory) {
[notifier notifyFailureWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Flat package does not exist at %@", self.flatPackagePath]}]]; [notifier notifyFailureWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Flat package does not exist at %@", self.flatPackagePath]}]];
} else { } else {
[notifier notifyProgress:1.0]; // Copying the flat package should be very fast, especially on APFS
[notifier notifySuccess]; NSError *copyError = nil;
if (![[NSFileManager defaultManager] copyItemAtPath:self.flatPackagePath toPath:[self.extractionDirectory stringByAppendingPathComponent:self.flatPackagePath.lastPathComponent] error:&copyError]) {
NSMutableDictionary *userInfoDictionary = [NSMutableDictionary dictionaryWithDictionary:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Flat package (%@) cannot be copied to extraction directory (%@)", self.flatPackagePath, self.extractionDirectory]}];
if (copyError != nil) {
userInfoDictionary[NSUnderlyingErrorKey] = copyError;
}
[notifier notifyFailureWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:userInfoDictionary]];
} else {
[notifier notifyProgress:1.0];
[notifier notifySuccess];
}
} }
} }
+28 -13
View File
@@ -22,15 +22,6 @@
@implementation SUInstaller @implementation SUInstaller
+ (BOOL)isAliasFolderAtPath:(NSString *)path
{
NSNumber *aliasFlag = nil;
[[NSURL fileURLWithPath:path] getResourceValue:&aliasFlag forKey:NSURLIsAliasFileKey error:nil];
NSNumber *directoryFlag = nil;
[[NSURL fileURLWithPath:path] getResourceValue:&directoryFlag forKey:NSURLIsDirectoryKey error:nil];
return aliasFlag.boolValue && directoryFlag.boolValue;
}
+ (nullable NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host isPackage:(BOOL *)isPackagePtr isGuided:(BOOL *)isGuidedPtr + (nullable NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host isPackage:(BOOL *)isPackagePtr isGuided:(BOOL *)isGuidedPtr
{ {
NSParameterAssert(inUpdateFolder); NSParameterAssert(inUpdateFolder);
@@ -49,6 +40,34 @@
while ((currentFile = [dirEnum nextObject])) { while ((currentFile = [dirEnum nextObject])) {
NSString *currentPath = [inUpdateFolder stringByAppendingPathComponent:currentFile]; NSString *currentPath = [inUpdateFolder stringByAppendingPathComponent:currentFile];
// Ignore all symbolic links and aliases
{
NSURL *currentPathURL = [NSURL fileURLWithPath:currentPath];
NSNumber *symbolicLinkFlag = nil;
[currentPathURL getResourceValue:&symbolicLinkFlag forKey:NSURLIsSymbolicLinkKey error:NULL];
if (symbolicLinkFlag.boolValue) {
// NSDirectoryEnumerator won't recurse into symlinked directories
continue;
}
NSNumber *aliasFlag = nil;
[currentPathURL getResourceValue:&aliasFlag forKey:NSURLIsAliasFileKey error:NULL];
if (aliasFlag.boolValue) {
NSNumber *directoryFlag = nil;
[currentPathURL getResourceValue:&directoryFlag forKey:NSURLIsDirectoryKey error:NULL];
// Some DMGs have symlinks into /Applications! That's no good!
if (directoryFlag.boolValue) {
[dirEnum skipDescendents];
}
continue;
}
}
NSString *currentFilename = [currentFile lastPathComponent]; NSString *currentFilename = [currentFile lastPathComponent];
NSString *currentExtension = [currentFile pathExtension]; NSString *currentExtension = [currentFile pathExtension];
NSString *currentFilenameNoExtension = [currentFilename stringByDeletingPathExtension]; NSString *currentFilenameNoExtension = [currentFilename stringByDeletingPathExtension];
@@ -78,10 +97,6 @@
break; break;
} }
} }
// Some DMGs have symlinks into /Applications! That's no good!
if ([self isAliasFolderAtPath:currentPath])
[dirEnum skipDescendents];
} }
// We don't have a valid path. Try to use the fallback package. // We don't have a valid path. Try to use the fallback package.
+1 -1
View File
@@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface SUPipedUnarchiver : NSObject <SUUnarchiverProtocol> @interface SUPipedUnarchiver : NSObject <SUUnarchiverProtocol>
- (instancetype)initWithArchivePath:(NSString *)archivePath; - (instancetype)initWithArchivePath:(NSString *)archivePath extractionDirectory:(NSString *)extractionDirectory;
@end @end
+5 -2
View File
@@ -17,12 +17,14 @@
@interface SUPipedUnarchiver () @interface SUPipedUnarchiver ()
@property (nonatomic, copy, readonly) NSString *archivePath; @property (nonatomic, copy, readonly) NSString *archivePath;
@property (nonatomic, copy, readonly) NSString *extractionDirectory;
@end @end
@implementation SUPipedUnarchiver @implementation SUPipedUnarchiver
@synthesize archivePath = _archivePath; @synthesize archivePath = _archivePath;
@synthesize extractionDirectory = _extractionDirectory;
+ (nullable NSArray <NSString *> *)commandAndArgumentsConformingToTypeOfPath:(NSString *)path + (nullable NSArray <NSString *> *)commandAndArgumentsConformingToTypeOfPath:(NSString *)path
{ {
@@ -63,11 +65,12 @@
return NO; return NO;
} }
- (instancetype)initWithArchivePath:(NSString *)archivePath - (instancetype)initWithArchivePath:(NSString *)archivePath extractionDirectory:(NSString *)extractionDirectory
{ {
self = [super init]; self = [super init];
if (self != nil) { if (self != nil) {
_archivePath = [archivePath copy]; _archivePath = [archivePath copy];
_extractionDirectory = [extractionDirectory copy];
} }
return self; return self;
} }
@@ -93,7 +96,7 @@
{ {
// *** GETS CALLED ON NON-MAIN THREAD!!! // *** GETS CALLED ON NON-MAIN THREAD!!!
@autoreleasepool { @autoreleasepool {
NSString *destination = [self.archivePath stringByDeletingLastPathComponent]; NSString *destination = self.extractionDirectory;
SULog(SULogLevelDefault, @"Extracting using '%@' '%@' < '%@' '%@'", command, [args componentsJoinedByString:@"' '"], self.archivePath, destination); SULog(SULogLevelDefault, @"Extracting using '%@' '%@' < '%@' '%@'", command, [args componentsJoinedByString:@"' '"], self.archivePath, destination);
+1 -1
View File
@@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface SUUnarchiver : NSObject @interface SUUnarchiver : NSObject
+ (nullable id <SUUnarchiverProtocol>)unarchiverForPath:(NSString *)path updatingHostBundlePath:(nullable NSString *)hostPath decryptionPassword:(nullable NSString *)decryptionPassword expectingInstallationType:(NSString *)installationType; + (nullable id <SUUnarchiverProtocol>)unarchiverForPath:(NSString *)path extractionDirectory:(NSString *)extractionDirectory updatingHostBundlePath:(nullable NSString *)hostPath decryptionPassword:(nullable NSString *)decryptionPassword expectingInstallationType:(NSString *)installationType;
@end @end
+5 -5
View File
@@ -18,21 +18,21 @@
@implementation SUUnarchiver @implementation SUUnarchiver
+ (nullable id <SUUnarchiverProtocol>)unarchiverForPath:(NSString *)path updatingHostBundlePath:(nullable NSString *)hostPath decryptionPassword:(nullable NSString *)decryptionPassword expectingInstallationType:(NSString *)installationType + (nullable id <SUUnarchiverProtocol>)unarchiverForPath:(NSString *)path extractionDirectory:(NSString *)extractionDirectory updatingHostBundlePath:(nullable NSString *)hostPath decryptionPassword:(nullable NSString *)decryptionPassword expectingInstallationType:(NSString *)installationType
{ {
if ([SUPipedUnarchiver canUnarchivePath:path]) { if ([SUPipedUnarchiver canUnarchivePath:path]) {
return [[SUPipedUnarchiver alloc] initWithArchivePath:path]; return [[SUPipedUnarchiver alloc] initWithArchivePath:path extractionDirectory:extractionDirectory];
} else if ([SUDiskImageUnarchiver canUnarchivePath:path]) { } else if ([SUDiskImageUnarchiver canUnarchivePath:path]) {
return [[SUDiskImageUnarchiver alloc] initWithArchivePath:path decryptionPassword:decryptionPassword]; return [[SUDiskImageUnarchiver alloc] initWithArchivePath:path extractionDirectory:extractionDirectory decryptionPassword:decryptionPassword];
} else if ([SUBinaryDeltaUnarchiver canUnarchivePath:path]) { } else if ([SUBinaryDeltaUnarchiver canUnarchivePath:path]) {
assert(hostPath != nil); assert(hostPath != nil);
NSString *nonNullHostPath = hostPath; NSString *nonNullHostPath = hostPath;
return [[SUBinaryDeltaUnarchiver alloc] initWithArchivePath:path updateHostBundlePath:nonNullHostPath]; return [[SUBinaryDeltaUnarchiver alloc] initWithArchivePath:path extractionDirectory:extractionDirectory updateHostBundlePath:nonNullHostPath];
} else if ([SUFlatPackageUnarchiver canUnarchivePath:path]) { } else if ([SUFlatPackageUnarchiver canUnarchivePath:path]) {
// Flat packages are only supported for guided packaage installs // Flat packages are only supported for guided packaage installs
return [[SUFlatPackageUnarchiver alloc] initWithFlatPackagePath:path expectingInstallationType:installationType]; return [[SUFlatPackageUnarchiver alloc] initWithFlatPackagePath:path extractionDirectory:extractionDirectory expectingInstallationType:installationType];
} }
return nil; return nil;
} }
+5 -1
View File
@@ -28,7 +28,11 @@ int main(int __unused argc, const char __unused *argv[])
dispatch_source_t sigtermSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGTERM, 0, dispatch_get_main_queue()); dispatch_source_t sigtermSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGTERM, 0, dispatch_get_main_queue());
dispatch_source_set_event_handler(sigtermSource, ^{ dispatch_source_set_event_handler(sigtermSource, ^{
[appInstaller cleanupAndExitWithStatus:SIGTERM error:nil]; // Don't clear the update directory because the installer may be in middle of installing an update
// We still need to set an event handler for receiving SIGTERM though, otherwise our job may not terminate
// (This is also recommended from the developer documentation).
// Simply exit with SIGTERM if we recieve this signal
exit(SIGTERM);
}); });
dispatch_resume(sigtermSource); dispatch_resume(sigtermSource);
+6 -11
View File
@@ -24,10 +24,9 @@ class SUUnarchiverTest: XCTestCase
let unarchivedSuccessExpectation = super.expectation(description: "Unarchived Success (format: \(archiveExtension))") let unarchivedSuccessExpectation = super.expectation(description: "Unarchived Success (format: \(archiveExtension))")
let unarchivedFailureExpectation = super.expectation(description: "Unarchived Failure (format: \(archiveExtension))") let unarchivedFailureExpectation = super.expectation(description: "Unarchived Failure (format: \(archiveExtension))")
let tempArchiveURL = tempDirectoryURL.appendingPathComponent(archiveResourceURL.lastPathComponent)
let extractedAppURL = tempDirectoryURL.appendingPathComponent(extractedAppName).appendingPathExtension("app") let extractedAppURL = tempDirectoryURL.appendingPathComponent(extractedAppName).appendingPathExtension("app")
self.unarchiveTestAppWithExtension(archiveExtension, appName: appName, tempDirectoryURL: tempDirectoryURL, tempArchiveURL: tempArchiveURL, archiveResourceURL: archiveResourceURL, password: password, expectingInstallationType: installationType, expectingSuccess: expectingSuccess, testExpectation: unarchivedSuccessExpectation) 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.unarchiveNonExistentFileTestFailureAppWithExtension(archiveExtension, tempDirectoryURL: tempDirectoryURL, password: password, expectingInstallationType: installationType, testExpectation: unarchivedFailureExpectation)
super.waitForExpectations(timeout: 30.0, handler: nil) super.waitForExpectations(timeout: 30.0, handler: nil)
@@ -40,7 +39,7 @@ class SUUnarchiverTest: XCTestCase
func unarchiveNonExistentFileTestFailureAppWithExtension(_ archiveExtension: String, tempDirectoryURL: URL, password: String?, expectingInstallationType installationType: String, testExpectation: XCTestExpectation) { func unarchiveNonExistentFileTestFailureAppWithExtension(_ archiveExtension: String, tempDirectoryURL: URL, password: String?, expectingInstallationType installationType: String, testExpectation: XCTestExpectation) {
let tempArchiveURL = tempDirectoryURL.appendingPathComponent("error-invalid").appendingPathExtension(archiveExtension) let tempArchiveURL = tempDirectoryURL.appendingPathComponent("error-invalid").appendingPathExtension(archiveExtension)
let unarchiver = SUUnarchiver.unarchiver(forPath: tempArchiveURL.path, updatingHostBundlePath: nil, decryptionPassword: password, expectingInstallationType: installationType)! let unarchiver = SUUnarchiver.unarchiver(forPath: tempArchiveURL.path, extractionDirectory: tempDirectoryURL.path, updatingHostBundlePath: nil, decryptionPassword: password, expectingInstallationType: installationType)!
unarchiver.unarchive(completionBlock: {(error: Error?) -> Void in unarchiver.unarchive(completionBlock: {(error: Error?) -> Void in
XCTAssertNotNil(error) XCTAssertNotNil(error)
@@ -49,13 +48,9 @@ class SUUnarchiverTest: XCTestCase
} }
// swiftlint:disable function_parameter_count // swiftlint:disable function_parameter_count
func unarchiveTestAppWithExtension(_ archiveExtension: String, appName: String, tempDirectoryURL: URL, tempArchiveURL: URL, archiveResourceURL: URL, password: String?, expectingInstallationType installationType: String, expectingSuccess: Bool, testExpectation: XCTestExpectation) { func unarchiveTestAppWithExtension(_ archiveExtension: String, appName: String, tempDirectoryURL: URL, archiveResourceURL: URL, password: String?, expectingInstallationType installationType: String, expectingSuccess: Bool, testExpectation: XCTestExpectation) {
let fileManager = FileManager.default let unarchiver = SUUnarchiver.unarchiver(forPath: archiveResourceURL.path, extractionDirectory: tempDirectoryURL.path, updatingHostBundlePath: nil, decryptionPassword: password, expectingInstallationType: installationType)!
try! fileManager.copyItem(at: archiveResourceURL, to: tempArchiveURL)
let unarchiver = SUUnarchiver.unarchiver(forPath: tempArchiveURL.path, updatingHostBundlePath: nil, decryptionPassword: password, expectingInstallationType: installationType)!
unarchiver.unarchive(completionBlock: {(error: Error?) -> Void in unarchiver.unarchive(completionBlock: {(error: Error?) -> Void in
if expectingSuccess { if expectingSuccess {
@@ -130,7 +125,7 @@ class SUUnarchiverTest: XCTestCase
self.unarchiveTestAppWithExtension("dmg", resourceName: "SparkleTestCodeSign_apfs") self.unarchiveTestAppWithExtension("dmg", resourceName: "SparkleTestCodeSign_apfs")
} }
func testUnarchivingFlatPackage() func testUnarchivingBarePackage()
{ {
self.unarchiveTestAppWithExtension("pkg", resourceName: "test", expectingInstallationType: SPUInstallationTypeGuidedPackage) self.unarchiveTestAppWithExtension("pkg", resourceName: "test", expectingInstallationType: SPUInstallationTypeGuidedPackage)
+16 -28
View File
@@ -8,38 +8,26 @@ import Foundation
func unarchive(itemPath: URL, archiveDestDir: URL, callback: @escaping (Error?) -> Void) { func unarchive(itemPath: URL, archiveDestDir: URL, callback: @escaping (Error?) -> Void) {
let fileManager = FileManager.default let fileManager = FileManager.default
let tempDir = archiveDestDir.appendingPathExtension("tmp") let tempDir = archiveDestDir.appendingPathExtension("tmp")
let itemCopy = tempDir.appendingPathComponent(itemPath.lastPathComponent)
_ = try? fileManager.removeItem(at: tempDir)
_ = try? fileManager.createDirectory(at: tempDir, withIntermediateDirectories: true, attributes: [:]) _ = try? fileManager.createDirectory(at: tempDir, withIntermediateDirectories: true, attributes: [:])
do { if let unarchiver = SUUnarchiver.unarchiver(forPath: itemPath.path, extractionDirectory: tempDir.path, updatingHostBundlePath: nil, decryptionPassword: nil, expectingInstallationType: SPUInstallationTypeApplication) {
do { unarchiver.unarchive(completionBlock: { (error: Error?) in
try fileManager.linkItem(at: itemPath, to: itemCopy) if error != nil {
} catch { callback(error)
try fileManager.copyItem(at: itemPath, to: itemCopy) return
} }
if let unarchiver = SUUnarchiver.unarchiver(forPath: itemCopy.path, updatingHostBundlePath: nil, decryptionPassword: nil, expectingInstallationType: SPUInstallationTypeApplication) {
unarchiver.unarchive(completionBlock: { (error: Error?) in
if error != nil {
callback(error)
return
}
_ = try? fileManager.removeItem(at: itemCopy) do {
do { try fileManager.moveItem(at: tempDir, to: archiveDestDir)
try fileManager.moveItem(at: tempDir, to: archiveDestDir) callback(nil)
callback(nil) } catch {
} catch { callback(error)
callback(error) }
} }, progressBlock: nil)
}, progressBlock: nil) } else {
} else { callback(makeError(code: .unarchivingError, "Not a supported archive format: \(itemPath.path)"))
_ = try? fileManager.removeItem(at: itemCopy)
callback(makeError(code: .unarchivingError, "Not a supported archive format: \(itemCopy)"))
}
} catch {
_ = try? fileManager.removeItem(at: tempDir)
callback(error)
} }
} }