From c0bb61cc8ff16743bfe4772f9866ac04c7406ee6 Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 3 May 2024 21:47:42 +0200 Subject: [PATCH] Revert unarchiver code to how it used to work in generate_appcast --- generate_appcast/Unarchive.swift | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/generate_appcast/Unarchive.swift b/generate_appcast/Unarchive.swift index 0c3c9c58..f501da6c 100644 --- a/generate_appcast/Unarchive.swift +++ b/generate_appcast/Unarchive.swift @@ -6,17 +6,28 @@ import Foundation func unarchive(itemPath: URL, archiveDestDir: URL, callback: @escaping (Error?) -> Void) { - if let unarchiver = SUUnarchiver.unarchiver(forPath: itemPath.path, extractionDirectory: archiveDestDir.path, updatingHostBundlePath: nil, decryptionPassword: nil, expectingInstallationType: SPUInstallationTypeApplication) { + let fileManager = FileManager.default + let tempDir = archiveDestDir.appendingPathExtension("tmp") + + _ = try? fileManager.removeItem(at: tempDir) + _ = try? fileManager.createDirectory(at: tempDir, withIntermediateDirectories: true, attributes: [:]) + + 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) return } - - callback(nil) + + do { + try fileManager.moveItem(at: tempDir, to: archiveDestDir) + callback(nil) + } catch { + callback(error) + } }, progressBlock: nil) } else { - callback(makeError(code: .unarchivingError, "Not a supported archive format: \(itemPath)")) + callback(makeError(code: .unarchivingError, "Not a supported archive format: \(itemPath.path)")) } }