Adds option to not cache downloaded app during installation

This commit is contained in:
Riley Testut
2020-05-15 14:55:15 -07:00
parent 7cbe921020
commit 7c9d8bd90d
2 changed files with 18 additions and 7 deletions

View File

@@ -486,7 +486,7 @@ private extension AppManager
return group
}
private func _install(_ app: AppProtocol, operation: AppOperation, group: RefreshGroup, additionalEntitlements: [ALTEntitlement: Any]? = nil, completionHandler: @escaping (Result<InstalledApp, Error>) -> Void) -> Progress
private func _install(_ app: AppProtocol, operation: AppOperation, group: RefreshGroup, additionalEntitlements: [ALTEntitlement: Any]? = nil, cacheApp: Bool = true, completionHandler: @escaping (Result<InstalledApp, Error>) -> Void) -> Progress
{
let progress = Progress.discreteProgress(totalUnitCount: 100)
@@ -514,13 +514,24 @@ private extension AppManager
downloadingApp = storeApp
}
let downloadedAppURL = context.temporaryDirectory.appendingPathComponent("Cached.app")
/* Download */
let downloadOperation = DownloadAppOperation(app: downloadingApp, context: context)
let downloadOperation = DownloadAppOperation(app: downloadingApp, destinationURL: downloadedAppURL, context: context)
downloadOperation.resultHandler = { (result) in
switch result
do
{
case .failure(let error): context.error = error
case .success(let app): context.app = app
let app = try result.get()
context.app = app
if cacheApp
{
try FileManager.default.copyItem(at: app.fileURL, to: InstalledApp.fileURL(for: app), shouldReplace: true)
}
}
catch
{
context.error = error
}
}
progress.addChild(downloadOperation.progress, withPendingUnitCount: 25)

View File

@@ -23,14 +23,14 @@ class DownloadAppOperation: ResultOperation<ALTApplication>
private let session = URLSession(configuration: .default)
init(app: AppProtocol, context: AppOperationContext)
init(app: AppProtocol, destinationURL: URL, context: AppOperationContext)
{
self.app = app
self.context = context
self.bundleIdentifier = app.bundleIdentifier
self.sourceURL = app.url
self.destinationURL = InstalledApp.fileURL(for: app)
self.destinationURL = destinationURL
super.init()