diff --git a/Autoupdate/AppInstaller.m b/Autoupdate/AppInstaller.m index b85857c5..0416eb93 100644 --- a/Autoupdate/AppInstaller.m +++ b/Autoupdate/AppInstaller.m @@ -247,15 +247,8 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7; [_communicator handleMessageWithIdentifier:SPUExtractionStarted data:[NSData data]]; NSString *archivePath = [_updateDirectoryPath stringByAppendingPathComponent:_downloadName]; - - NSString *extractionMountDirectory; - if ([SUUnarchiver requiresExtractionMountDirectory:archivePath]) { - extractionMountDirectory = [SPULocalCacheDirectory createUniqueDirectoryInDirectory:_updateDirectoryPath]; - } else { - extractionMountDirectory = nil; - } - - id unarchiver = [SUUnarchiver unarchiverForPath:archivePath extractionDirectory:_extractionDirectory extractionMountDirectory:extractionMountDirectory updatingHostBundlePath:_host.bundlePath decryptionPassword:_decryptionPassword expectingInstallationType:_installationType]; + + id unarchiver = [SUUnarchiver unarchiverForPath:archivePath extractionDirectory:_extractionDirectory updatingHostBundlePath:_host.bundlePath decryptionPassword:_decryptionPassword expectingInstallationType:_installationType]; NSError *prevalidationError = nil; BOOL success = NO; diff --git a/Autoupdate/SUDiskImageUnarchiver.h b/Autoupdate/SUDiskImageUnarchiver.h index e8ef3136..51185669 100644 --- a/Autoupdate/SUDiskImageUnarchiver.h +++ b/Autoupdate/SUDiskImageUnarchiver.h @@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN SPU_OBJC_DIRECT_MEMBERS @interface SUDiskImageUnarchiver : NSObject -- (instancetype)initWithArchivePath:(NSString *)archivePath extractionDirectory:(NSString *)extractionDirectory extractionMountDirectory:(nullable NSString *)extractionMountDirectory decryptionPassword:(nullable NSString *)decryptionPassword; +- (instancetype)initWithArchivePath:(NSString *)archivePath extractionDirectory:(NSString *)extractionDirectory decryptionPassword:(nullable NSString *)decryptionPassword; + (BOOL)canUnarchivePath:(NSString *)path; diff --git a/Autoupdate/SUDiskImageUnarchiver.m b/Autoupdate/SUDiskImageUnarchiver.m index 6d587c4f..1fc39803 100644 --- a/Autoupdate/SUDiskImageUnarchiver.m +++ b/Autoupdate/SUDiskImageUnarchiver.m @@ -22,10 +22,8 @@ NSString *_archivePath; NSString *_decryptionPassword; NSString *_extractionDirectory; - NSString *_extractionMountDirectory; SUUnarchiverNotifier *_notifier; - double _currentExtractionProgress; double _fileProgressIncrement; } @@ -40,14 +38,13 @@ return NO; } -- (instancetype)initWithArchivePath:(NSString *)archivePath extractionDirectory:(NSString *)extractionDirectory extractionMountDirectory:(nullable NSString *)extractionMountDirectory decryptionPassword:(nullable NSString *)decryptionPassword +- (instancetype)initWithArchivePath:(NSString *)archivePath extractionDirectory:(NSString *)extractionDirectory decryptionPassword:(nullable NSString *)decryptionPassword { self = [super init]; if (self != nil) { _archivePath = [archivePath copy]; _decryptionPassword = [decryptionPassword copy]; _extractionDirectory = [extractionDirectory copy]; - _extractionMountDirectory = [extractionMountDirectory copy]; } return self; } @@ -89,30 +86,18 @@ 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; + NSString *mountPoint = nil; + NSFileManager *manager; NSError *error = nil; - 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; + NSArray *contents = nil; + 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]); NSMutableData *inputData = [NSMutableData data]; @@ -125,31 +110,20 @@ static NSUInteger fileCountForDirectory(NSFileManager *fileManager, NSString *it [inputData appendData:decryptionPasswordData]; } - 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]; - } - + // 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]; } - // Always pass -stdinpass / --stdinpassphrase so we gracefully handle password protected disk images even if we aren't expecting them - NSArray *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"]; - } + // 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"]; NSData *output = nil; NSInteger taskResult = -1; @@ -159,20 +133,12 @@ static NSUInteger fileCountForDirectory(NSFileManager *fileManager, NSString *it NSMutableArray *itemsToExtract = [NSMutableArray array]; NSUInteger totalFileExtractionCount = 0; - NSFileManager *manager = nil; - NSArray *contents = nil; - BOOL success = YES; { NSTask *task = [[NSTask alloc] init]; - if (useModernDiskUtilImplementation) { - task.executableURL = [NSURL fileURLWithPath:@"/usr/sbin/diskutil" isDirectory:NO]; - } else { - task.executableURL = [NSURL fileURLWithPath:@"/usr/bin/hdiutil" isDirectory:NO]; - task.currentDirectoryPath = @"/"; - } - + task.launchPath = @"/usr/bin/hdiutil"; + task.currentDirectoryPath = @"/"; task.arguments = arguments; NSPipe *inputPipe = [NSPipe pipe]; @@ -213,9 +179,9 @@ static NSUInteger fileCountForDirectory(NSFileManager *fileManager, NSString *it if (taskResult != 0) { NSString *resultStr = output ? [[NSString alloc] initWithData:output encoding:NSUTF8StringEncoding] : nil; - SULog(SULogLevelError, @"%@ failed with code: %ld data: <<%@>>", (useModernDiskUtilImplementation ? @"diskutil" : @"hdiutil"), (long)taskResult, resultStr); + SULog(SULogLevelError, @"hdiutil failed with code: %ld data: <<%@>>", (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]}]; + error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Extraction failed due to hdiutil returning %ld status: %@", (long)taskResult, resultStr]}]; goto reportError; } @@ -318,20 +284,14 @@ static NSUInteger fileCountForDirectory(NSFileManager *fileManager, NSString *it finally: if (mountedSuccessfully) { NSTask *task = [[NSTask alloc] init]; - - if (useModernDiskUtilImplementation) { - task.launchPath = @"/usr/sbin/diskutil"; - task.arguments = @[@"eject", mountPoint]; - } else { - task.launchPath = @"/usr/bin/hdiutil"; - task.arguments = @[@"detach", mountPoint, @"-force"]; - } + 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 %@", (useModernDiskUtilImplementation ? @"diskutil" : @"hdiutil"), mountPoint); + SULog(SULogLevelError, @"Failed to unmount %@", mountPoint); SULog(SULogLevelError, @"Error: %@", launchCleanupError); } else if (waitForCleanup) { [task waitUntilExit]; diff --git a/Autoupdate/SUUnarchiver.h b/Autoupdate/SUUnarchiver.h index 7e684d26..ced34682 100644 --- a/Autoupdate/SUUnarchiver.h +++ b/Autoupdate/SUUnarchiver.h @@ -14,10 +14,7 @@ NS_ASSUME_NONNULL_BEGIN SPU_OBJC_DIRECT_MEMBERS @interface SUUnarchiver : NSObject -+ (nullable id )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 requires an extraction mount directory to be provided to -unarchiverForPath:extractionDirectory:extractionMountDirectory:updatingHostBundlePath:decryptionPassword:expectingInstallationType: -+ (BOOL)requiresExtractionMountDirectory:(NSString *)path; ++ (nullable id )unarchiverForPath:(NSString *)path extractionDirectory:(NSString *)extractionDirectory updatingHostBundlePath:(nullable NSString *)hostPath decryptionPassword:(nullable NSString *)decryptionPassword expectingInstallationType:(NSString *)installationType; @end diff --git a/Autoupdate/SUUnarchiver.m b/Autoupdate/SUUnarchiver.m index baf9b122..0f0121a9 100644 --- a/Autoupdate/SUUnarchiver.m +++ b/Autoupdate/SUUnarchiver.m @@ -18,28 +18,13 @@ @implementation SUUnarchiver -+ (BOOL)requiresExtractionMountDirectory:(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+ - if (@available(macOS 27, *)) { - return YES; - } else { - return NO; - } -} - -+ (nullable id )unarchiverForPath:(NSString *)path extractionDirectory:(NSString *)extractionDirectory extractionMountDirectory:(nullable NSString *)extractionMountDirectory updatingHostBundlePath:(nullable NSString *)hostPath decryptionPassword:(nullable NSString *)decryptionPassword expectingInstallationType:(NSString *)installationType ++ (nullable id )unarchiverForPath:(NSString *)path extractionDirectory:(NSString *)extractionDirectory 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 extractionMountDirectory:extractionMountDirectory decryptionPassword:decryptionPassword]; + return [[SUDiskImageUnarchiver alloc] initWithArchivePath:path extractionDirectory:extractionDirectory decryptionPassword:decryptionPassword]; } else if ([SUBinaryDeltaUnarchiver canUnarchivePath:path]) { assert(hostPath != nil); diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 65a808e4..598776a1 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -410,6 +410,8 @@ 72C56E1F2F04AC890005A484 /* SUFeedSignatureVerifierTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72C56E1E2F04AC890005A484 /* SUFeedSignatureVerifierTest.swift */; }; 72C56E202F04B3760005A484 /* Signing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72C56E0F2EFEF10B0005A484 /* Signing.swift */; }; 72C56E262F04C28B0005A484 /* testreleasenotes.html in Resources */ = {isa = PBXBuildFile; fileRef = 72C56E212F04C28B0005A484 /* testreleasenotes.html */; }; + 72C6F2DB303BE56100D39EF2 /* SparkleTestCodeSignApp.license.no-text.dmg in Resources */ = {isa = PBXBuildFile; fileRef = 72C6F2D8303BE56100D39EF2 /* SparkleTestCodeSignApp.license.no-text.dmg */; }; + 72C6F2DD303BE80200D39EF2 /* SparkleTestCodeSignApp.license.large-formatted-multi-lang-text.dmg in Resources */ = {isa = PBXBuildFile; fileRef = 72C6F2DC303BE80200D39EF2 /* SparkleTestCodeSignApp.license.large-formatted-multi-lang-text.dmg */; }; 72CCDEBE27421FD500B53718 /* SparkleTestCodeSignApp_bad_header.zip in Resources */ = {isa = PBXBuildFile; fileRef = 72CCDEBD27421FD500B53718 /* SparkleTestCodeSignApp_bad_header.zip */; }; 72D04F3D2B094C8400A6DEAA /* SPUVerifierInformation.m in Sources */ = {isa = PBXBuildFile; fileRef = 72D04F3C2B094C8400A6DEAA /* SPUVerifierInformation.m */; }; 72D04F3E2B097D4300A6DEAA /* SPUVerifierInformation.m in Sources */ = {isa = PBXBuildFile; fileRef = 72D04F3C2B094C8400A6DEAA /* SPUVerifierInformation.m */; }; @@ -1349,6 +1351,8 @@ 72C56E182F04343D0005A484 /* SPUAppcastSigningValidationStatus.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SPUAppcastSigningValidationStatus.h; sourceTree = ""; }; 72C56E1E2F04AC890005A484 /* SUFeedSignatureVerifierTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SUFeedSignatureVerifierTest.swift; sourceTree = ""; }; 72C56E212F04C28B0005A484 /* testreleasenotes.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = testreleasenotes.html; sourceTree = ""; }; + 72C6F2D8303BE56100D39EF2 /* SparkleTestCodeSignApp.license.no-text.dmg */ = {isa = PBXFileReference; lastKnownFileType = file; path = "SparkleTestCodeSignApp.license.no-text.dmg"; sourceTree = ""; }; + 72C6F2DC303BE80200D39EF2 /* SparkleTestCodeSignApp.license.large-formatted-multi-lang-text.dmg */ = {isa = PBXFileReference; lastKnownFileType = file; path = "SparkleTestCodeSignApp.license.large-formatted-multi-lang-text.dmg"; sourceTree = ""; }; 72CCDEBD27421FD500B53718 /* SparkleTestCodeSignApp_bad_header.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = SparkleTestCodeSignApp_bad_header.zip; sourceTree = ""; }; 72D04F3B2B094C8400A6DEAA /* SPUVerifierInformation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SPUVerifierInformation.h; sourceTree = ""; }; 72D04F3C2B094C8400A6DEAA /* SPUVerifierInformation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SPUVerifierInformation.m; sourceTree = ""; }; @@ -1827,6 +1831,8 @@ F8761EB21ADC50EB000C9034 /* SparkleTestCodeSignApp.zip */, 726FC0352C1E787A00177986 /* SparkleTestCodeSignApp.aar */, 726FC0372C1E96AA00177986 /* SparkleTestCodeSignApp.enc.aar */, + 72C6F2D8303BE56100D39EF2 /* SparkleTestCodeSignApp.license.no-text.dmg */, + 72C6F2DC303BE80200D39EF2 /* SparkleTestCodeSignApp.license.large-formatted-multi-lang-text.dmg */, 72EB735E29BE981300FBCEE7 /* DevSignedApp.zip */, 72EB736029BEB36100FBCEE7 /* DevSignedAppVersion2.zip */, 726B20602CF4F1D300E6F7DB /* DevSignedAppVersion2.dmg */, @@ -3146,6 +3152,7 @@ 723EDC3F26885A8E000BCBA4 /* testappcast_channels.xml in Resources */, 720DC50427A51A6500DFF3EC /* testappcast_minimumAutoupdateVersionSkipping.xml in Resources */, 72E6D9712C04DE1A005496E4 /* SparkleTestCodeSign_pkg.dmg in Resources */, + 72C6F2DD303BE80200D39EF2 /* SparkleTestCodeSignApp.license.large-formatted-multi-lang-text.dmg in Resources */, 72526BE62EF3349D005791ED /* testappcast_minimumUpdateVersion.xml in Resources */, 72AC6B2E1B9B218C00F62325 /* SparkleTestCodeSignApp.dmg in Resources */, C23E885B1BE7B24F0050BB73 /* SparkleTestCodeSignApp.enc.dmg in Resources */, @@ -3173,6 +3180,7 @@ 722545B626805FF80036465C /* testappcast_info_updates.xml in Resources */, 723414172EBFB482009727E0 /* testappcast_arm64HardwareRequirement.xml in Resources */, 7202DC9A269ABD3500737EC4 /* testappcast_phasedRollout.xml in Resources */, + 72C6F2DB303BE56100D39EF2 /* SparkleTestCodeSignApp.license.no-text.dmg in Resources */, 5F1510A21C96E591006E1629 /* testnamespaces.xml in Resources */, 729F7EAC27366353004592DC /* test-links.xml in Resources */, ); diff --git a/Tests/Resources/SparkleTestCodeSignApp.license.large-formatted-multi-lang-text.dmg b/Tests/Resources/SparkleTestCodeSignApp.license.large-formatted-multi-lang-text.dmg new file mode 100644 index 00000000..c704840e Binary files /dev/null and b/Tests/Resources/SparkleTestCodeSignApp.license.large-formatted-multi-lang-text.dmg differ diff --git a/Tests/Resources/SparkleTestCodeSignApp.license.no-text.dmg b/Tests/Resources/SparkleTestCodeSignApp.license.no-text.dmg new file mode 100644 index 00000000..88ea8aef Binary files /dev/null and b/Tests/Resources/SparkleTestCodeSignApp.license.no-text.dmg differ diff --git a/Tests/SUUnarchiverTest.swift b/Tests/SUUnarchiverTest.swift index f3e3388f..f872c01e 100644 --- a/Tests/SUUnarchiverTest.swift +++ b/Tests/SUUnarchiverTest.swift @@ -45,11 +45,8 @@ class SUUnarchiverTest: XCTestCase func unarchiveNonExistentFileTestFailureAppWithExtension(_ archiveExtension: String, tempDirectoryURL: URL, password: String?, expectingInstallationType installationType: String, testExpectation: XCTestExpectation) { let tempArchiveURL = tempDirectoryURL.deletingLastPathComponent().appendingPathComponent("error-invalid").appendingPathExtension(archiveExtension) - - // The disk image unarchiver will create and remove this directory automatically - let extractionMountDirectory: String? = SUUnarchiver.requiresExtractionMountDirectory(tempArchiveURL.path) ? 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)! + + let unarchiver = SUUnarchiver.unarchiver(forPath: tempArchiveURL.path, extractionDirectory: tempDirectoryURL.path, updatingHostBundlePath: nil, decryptionPassword: password, expectingInstallationType: installationType)! unarchiver.unarchive(completionBlock: {(error: Error?) -> Void in XCTAssertNotNil(error) @@ -59,11 +56,8 @@ class SUUnarchiverTest: XCTestCase // swiftlint:disable function_parameter_count func unarchiveTestAppWithExtension(_ archiveExtension: String, appName: String, tempDirectoryURL: URL, archiveResourceURL: URL, password: String?, expectingInstallationType installationType: String, expectingSuccess: Bool, testExpectation: XCTestExpectation) { - - // The disk image unarchiver will create and remove this directory automatically - let extractionMountDirectory: String? = SUUnarchiver.requiresExtractionMountDirectory(archiveResourceURL.path) ? 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)! + + let unarchiver = SUUnarchiver.unarchiver(forPath: archiveResourceURL.path, extractionDirectory: tempDirectoryURL.path, updatingHostBundlePath: nil, decryptionPassword: password, expectingInstallationType: installationType)! unarchiver.unarchive(completionBlock: {(error: Error?) -> Void in if expectingSuccess { @@ -178,6 +172,16 @@ class SUUnarchiverTest: XCTestCase self.unarchiveTestAppWithExtension("dmg", resourceName: "SparkleTestCodeSign_pkg", expectingInstallationType: SPUInstallationTypeGuidedPackage) } + func testUnarchivingLicensedDMGWithNoText() + { + self.unarchiveTestAppWithExtension("license.no-text.dmg") + } + + func testUnarchivingLicensedDMGWithMultipleLanaguesAndLotsOfFormattedText() + { + self.unarchiveTestAppWithExtension("license.large-formatted-multi-lang-text.dmg") + } + #if SPARKLE_BUILD_PACKAGE_SUPPORT func testUnarchivingBarePackage() { diff --git a/generate_appcast/Unarchive.swift b/generate_appcast/Unarchive.swift index 88b0bc79..5d2303a8 100644 --- a/generate_appcast/Unarchive.swift +++ b/generate_appcast/Unarchive.swift @@ -7,15 +7,12 @@ import Foundation func unarchive(itemPath: URL, archiveDestDir: URL, callback: @escaping (Error?) -> Void) { let fileManager = FileManager.default - let tempExtractionDir = archiveDestDir.appendingPathExtension("tmp") + let tempDir = archiveDestDir.appendingPathExtension("tmp") - _ = 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.requiresExtractionMountDirectory(itemPath.path) ? URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true).appendingPathComponent(ProcessInfo.processInfo.globallyUniqueString).path : nil + _ = try? fileManager.removeItem(at: tempDir) + _ = try? fileManager.createDirectory(at: tempDir, withIntermediateDirectories: true, attributes: [:]) - if let unarchiver = SUUnarchiver.unarchiver(forPath: itemPath.path, extractionDirectory: tempExtractionDir.path, extractionMountDirectory: extractionMountDirectory, updatingHostBundlePath: nil, decryptionPassword: nil, expectingInstallationType: SPUInstallationTypeApplication) { + if let unarchiver = SUUnarchiver.unarchiver(forPath: itemPath.path, extractionDirectory: tempDir.path, updatingHostBundlePath: nil, decryptionPassword: nil, expectingInstallationType: SPUInstallationTypeApplication) { unarchiver.unarchive(completionBlock: { (error: Error?) in if error != nil { callback(error) @@ -23,7 +20,7 @@ func unarchive(itemPath: URL, archiveDestDir: URL, callback: @escaping (Error?) } do { - try fileManager.moveItem(at: tempExtractionDir, to: archiveDestDir) + try fileManager.moveItem(at: tempDir, to: archiveDestDir) callback(nil) } catch { callback(error)