From f5b63b52b491986d91fc841313012b14f578c348 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Mon, 29 May 2023 18:15:16 -0500 Subject: [PATCH] =?UTF-8?q?Fixes=20=E2=80=9CCheck=20for=20Updates=E2=80=9D?= =?UTF-8?q?=20not=20updating=20any=20sources=20if=20one=20source=20fails?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AltStore/My Apps/MyAppsViewController.swift | 56 ++++++++++++--------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/AltStore/My Apps/MyAppsViewController.swift b/AltStore/My Apps/MyAppsViewController.swift index 391eca44..4011fab4 100644 --- a/AltStore/My Apps/MyAppsViewController.swift +++ b/AltStore/My Apps/MyAppsViewController.swift @@ -1502,40 +1502,46 @@ private extension MyAppsViewController } } - let (_, context) = try await result - - try await context.performAsync { + do + { do { - try context.save() + let (_, context) = try await result + + try await context.performAsync { + try context.save() + } } catch let error as AppManager.FetchSourcesError { - try error.managedObjectContext?.save() - throw error - } - catch let mergeError as MergeError - { - guard let sourceID = mergeError.sourceID else { throw mergeError } - - let sanitizedError = (mergeError as NSError).sanitizedForSerialization() - DatabaseManager.shared.persistentContainer.performBackgroundTask { context in - do - { - guard let source = Source.first(satisfying: NSPredicate(format: "%K == %@", #keyPath(Source.identifier), sourceID), in: context) else { return } - - source.error = sanitizedError - try context.save() - } - catch - { - print("[ALTLog] Failed to assign error \(sanitizedError.localizedErrorCode) to source \(sourceID).", error) - } + try await error.managedObjectContext?.performAsync { + try error.managedObjectContext?.save() } - throw mergeError + throw error } } + catch let mergeError as MergeError + { + guard let sourceID = mergeError.sourceID else { throw mergeError } + + let sanitizedError = (mergeError as NSError).sanitizedForSerialization() + DatabaseManager.shared.persistentContainer.performBackgroundTask { context in + do + { + guard let source = Source.first(satisfying: NSPredicate(format: "%K == %@", #keyPath(Source.identifier), sourceID), in: context) else { return } + + source.error = sanitizedError + try context.save() + } + catch + { + print("[ALTLog] Failed to assign error \(sanitizedError.localizedErrorCode) to source \(sourceID).", error) + } + } + + throw mergeError + } } catch let error as NSError {