mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-16 18:23:53 +01:00
Fixes race condition when installing app with app groups + extensions
This commit is contained in:
@@ -16,6 +16,8 @@ class FetchProvisioningProfilesOperation: ResultOperation<[String: ALTProvisioni
|
|||||||
{
|
{
|
||||||
let context: AppOperationContext
|
let context: AppOperationContext
|
||||||
|
|
||||||
|
private let appGroupsLock = NSLock()
|
||||||
|
|
||||||
init(context: AppOperationContext)
|
init(context: AppOperationContext)
|
||||||
{
|
{
|
||||||
self.context = context
|
self.context = context
|
||||||
@@ -346,25 +348,36 @@ extension FetchProvisioningProfilesOperation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let adjustedGroupIdentifier = groupIdentifier + "." + team.identifier
|
// Dispatch onto global queue to prevent appGroupsLock deadlock.
|
||||||
|
DispatchQueue.global().async {
|
||||||
ALTAppleAPI.shared.fetchAppGroups(for: team, session: session) { (groups, error) in
|
let adjustedGroupIdentifier = groupIdentifier + "." + team.identifier
|
||||||
switch Result(groups, error)
|
|
||||||
{
|
// Ensure we're not concurrently fetching and updating app groups,
|
||||||
case .failure(let error): completionHandler(.failure(error))
|
// which can lead to race conditions such as adding an app group twice.
|
||||||
case .success(let groups):
|
self.appGroupsLock.lock()
|
||||||
|
|
||||||
if let group = groups.first(where: { $0.groupIdentifier == adjustedGroupIdentifier })
|
ALTAppleAPI.shared.fetchAppGroups(for: team, session: session) { (groups, error) in
|
||||||
|
switch Result(groups, error)
|
||||||
{
|
{
|
||||||
finish(.success(group))
|
case .failure(let error):
|
||||||
}
|
self.appGroupsLock.unlock()
|
||||||
else
|
completionHandler(.failure(error))
|
||||||
{
|
|
||||||
// Not all characters are allowed in group names, so we replace periods with spaces (like Apple does).
|
|
||||||
let name = "AltStore " + groupIdentifier.replacingOccurrences(of: ".", with: " ")
|
|
||||||
|
|
||||||
ALTAppleAPI.shared.addAppGroup(withName: name, groupIdentifier: adjustedGroupIdentifier, team: team, session: session) { (group, error) in
|
case .success(let groups):
|
||||||
finish(Result(group, error))
|
if let group = groups.first(where: { $0.groupIdentifier == adjustedGroupIdentifier })
|
||||||
|
{
|
||||||
|
self.appGroupsLock.unlock()
|
||||||
|
finish(.success(group))
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Not all characters are allowed in group names, so we replace periods with spaces (like Apple does).
|
||||||
|
let name = "AltStore " + groupIdentifier.replacingOccurrences(of: ".", with: " ")
|
||||||
|
|
||||||
|
ALTAppleAPI.shared.addAppGroup(withName: name, groupIdentifier: adjustedGroupIdentifier, team: team, session: session) { (group, error) in
|
||||||
|
self.appGroupsLock.unlock()
|
||||||
|
finish(Result(group, error))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user