From 2157d95c564b34f3f566f1e32faaefa48b8912bb Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Mon, 1 Mar 2021 12:45:57 -0600 Subject: [PATCH] Fixes serial operations not running in FIFO order Ensures AltStore is always the last app to be refreshed, which matters when AltStore needs to be resigned and reinstalled (such as when using AltDaemon on iOS 14). --- AltStore/Managing Apps/AppManager.swift | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/AltStore/Managing Apps/AppManager.swift b/AltStore/Managing Apps/AppManager.swift index f66d1f2b..7785f37d 100644 --- a/AltStore/Managing Apps/AppManager.swift +++ b/AltStore/Managing Apps/AppManager.swift @@ -1403,12 +1403,26 @@ private extension AppManager func run(_ operations: [Foundation.Operation], context: OperationContext?, requiresSerialQueue: Bool = false) { + // Reference to previous serial operation in context used to enforce FIFO, + // even if the operations become ready in a different order than submitted. + var previousSerialOperation: Foundation.Operation? = context?.operations.allObjects.filter { self.serialOperationQueue.operations.contains($0) }.last + for operation in operations { switch operation { case _ where requiresSerialQueue: fallthrough - case is InstallAppOperation, is RefreshAppOperation, is BackupAppOperation: self.serialOperationQueue.addOperation(operation) + case is InstallAppOperation, is RefreshAppOperation, is BackupAppOperation: + if let previousOperation = previousSerialOperation + { + // Add dependency on previous serial operation to enforce FIFO. + operation.addDependency(previousOperation) + } + + self.serialOperationQueue.addOperation(operation) + + previousSerialOperation = operation + default: self.operationQueue.addOperation(operation) }