Revert unarchiver code to how it used to work in generate_appcast (#2556)

Also remove temp directory before extraction.
This commit is contained in:
Zorg authored and GitHub committed 2024-05-05 21:50:25 -07:00
1 parent 56ad4aa3c8
commit d7db589432
1 file changed
+15 -4
+15 -4
View File
@@ -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) {
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) {
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)"))
}
}