diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension+ClientInterface.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension+ClientInterface.swift index a4b60a407..61f0a0605 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension+ClientInterface.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension+ClientInterface.swift @@ -134,7 +134,12 @@ extension FileProviderExtension: NSFileProviderServicing, ChangeNotificationInte } func updatedSyncStateReporting(oldActions: Set) { - guard oldActions.isEmpty != syncActions.isEmpty else { return } + actionsLock.lock() + + guard oldActions.isEmpty != syncActions.isEmpty else { + actionsLock.unlock() + return + } let command = "FILE_PROVIDER_DOMAIN_SYNC_STATE_CHANGE" var argument: String? @@ -144,6 +149,8 @@ extension FileProviderExtension: NSFileProviderServicing, ChangeNotificationInte argument = errorActions.isEmpty ? "SYNC_FINISHED" : "SYNC_FAILED" errorActions = [] } + + actionsLock.unlock() guard let argument else { return } Logger.fileProviderExtension.debug("Reporting sync \(argument)") diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension.swift index 1e648a244..533d20d56 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension.swift @@ -39,6 +39,7 @@ import OSLog var syncActions = Set() var errorActions = Set() + var actionsLock = NSLock() // Whether or not we are going to recursively scan new folders when they are discovered. // Apple's recommendation is that we should always scan the file hierarchy fully. @@ -71,22 +72,28 @@ import OSLog } func insertSyncAction(_ actionId: UUID) { + actionsLock.lock() let oldActions = syncActions syncActions.insert(actionId) + actionsLock.unlock() updatedSyncStateReporting(oldActions: oldActions) } func insertErrorAction(_ actionId: UUID) { + actionsLock.lock() let oldActions = syncActions syncActions.remove(actionId) errorActions.insert(actionId) + actionsLock.unlock() updatedSyncStateReporting(oldActions: oldActions) } func removeSyncAction(_ actionId: UUID) { + actionsLock.lock() let oldActions = syncActions syncActions.remove(actionId) errorActions.remove(actionId) + actionsLock.unlock() updatedSyncStateReporting(oldActions: oldActions) }