From 40e3408f5ed8d055c8af543f048e8b995c6eb643 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Tue, 28 Jul 2026 10:58:40 -0700 Subject: [PATCH] Fix iCloud sync progress leaks that left the Refresh button and menu item wrongly disabled. Fixes #4538. --- .../CloudKit/CloudKitAccountDelegate.swift | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift index 2278fe306..654fa479e 100644 --- a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift @@ -456,7 +456,9 @@ enum CloudKitAccountDelegateError: LocalizedError, Sendable { account.removeFolderFromTree(folder) try await account.logActivity(kind: .removeFolder, detail: folderName) { - syncProgress.addTask() + // Two tasks: finding the folder's feed externalIDs, removing the folder record. + // Every path below completes exactly two. + syncProgress.addTasks(2) let feedExternalIDs: [String] do { @@ -570,7 +572,9 @@ enum CloudKitAccountDelegateError: LocalizedError, Sendable { account.addFolderToTree(folder) } } catch { - syncProgress.completeTask() + // Only reachable when createFolder throws, before any of the + // 1 + feedsToRestore.count tasks completed — complete them all. + syncProgress.completeTasks(1 + feedsToRestore.count) postSyncError(error, account: account, operation: "Restoring folder") throw error } @@ -893,7 +897,9 @@ private extension CloudKitAccountDelegate { editedName: editedName, container: container) } catch { - syncProgress.completeTasks(3) + // When FeedFinder.find is what threw, none of the five tasks have completed yet — + // four here plus one more from the validateFeed path or addDeadFeed. + syncProgress.completeTasks(4) if validateFeed { syncProgress.completeTask() throw AccountError.createErrorNotFound @@ -991,6 +997,11 @@ private extension CloudKitAccountDelegate { func sendNewArticlesToTheCloud(_ account: Account, _ feed: Feed) { Self.logger.debug("CloudKitAccountDelegate: \(#function, privacy: .public)") Task { + // Completes createRSSFeed's fifth task. + // + defer { + syncProgress.completeTask() + } do { let articles = await account.fetchArticlesAsync(.feed(feed))