Fixes increasing app size when refreshing

We now delete temporary directory + resigned .ipa before installation is complete to ensure AltStore doesn’t quit before we have the chance to.
This commit is contained in:
Riley Testut
2019-12-11 12:26:48 -08:00
parent 48dfe5b2da
commit ae5ba81138
2 changed files with 37 additions and 4 deletions

View File

@@ -405,10 +405,7 @@ private extension AppManager
do { try installedApp.managedObjectContext?.save() }
catch { print("Error saving installed app.", error) }
}
}
do { try FileManager.default.removeItem(at: context.temporaryDirectory) }
catch { print("Failed to remove temporary directory.", error) }
}
print("Finished operation!", context.bundleIdentifier)

View File

@@ -18,6 +18,8 @@ class InstallAppOperation: ResultOperation<InstalledApp>
{
let context: AppOperationContext
private var didCleanUp = false
init(context: AppOperationContext)
{
self.context = context
@@ -65,6 +67,9 @@ class InstallAppOperation: ResultOperation<InstalledApp>
installedApp.expirationDate = profile.expirationDate
}
// Temporary directory and resigned .ipa no longer needed, so delete them now to ensure AltStore doesn't quit before we get the chance to.
self.cleanUp()
self.context.group.beginInstallationHandler?(installedApp)
let request = BeginInstallationRequest()
@@ -92,6 +97,16 @@ class InstallAppOperation: ResultOperation<InstalledApp>
}
}
override func finish(_ result: Result<InstalledApp, Error>)
{
self.cleanUp()
super.finish(result)
}
}
private extension InstallAppOperation
{
func receive(from connection: NWConnection, server: Server, completionHandler: @escaping (Result<Void, Error>) -> Void)
{
server.receiveResponse(from: connection) { (result) in
@@ -127,4 +142,25 @@ class InstallAppOperation: ResultOperation<InstalledApp>
}
}
}
func cleanUp()
{
guard !self.didCleanUp else { return }
self.didCleanUp = true
do
{
try FileManager.default.removeItem(at: self.context.temporaryDirectory)
if let app = self.context.app
{
let fileURL = InstalledApp.refreshedIPAURL(for: app)
try FileManager.default.removeItem(at: fileURL)
}
}
catch
{
print("Failed to remove temporary directory.", error)
}
}
}