Skip to content

Commit e8bd02e

Browse files
i2h3mgallien
authored andcommitted
fix(file-provider): Sync state for excluded lock files.
- Added debug logging to file provider extension about its sync actions. - Added debug logging to file provider extension about its sync state reported to the main app through the socket. - Added debug logging to the main app about the sync state received from a file provider extension through the socket. - Updated sync action management to not consider the exclusion of a lock file as an error. Signed-off-by: Iva Horn <[email protected]>
1 parent 848f6a1 commit e8bd02e

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension+ClientInterface.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,14 @@ extension FileProviderExtension: NSFileProviderServicing, ChangeNotificationInte
218218
actionsLock.lock()
219219

220220
guard oldActions.isEmpty != syncActions.isEmpty else {
221+
logger.debug("Cancelling synchronization state report due to lack of state change.")
221222
actionsLock.unlock()
222223
return
223224
}
224225

225226
let command = "FILE_PROVIDER_DOMAIN_SYNC_STATE_CHANGE"
226227
var argument: String?
228+
227229
if oldActions.isEmpty, !syncActions.isEmpty {
228230
argument = "SYNC_STARTED"
229231
} else if !oldActions.isEmpty, syncActions.isEmpty {
@@ -233,8 +235,13 @@ extension FileProviderExtension: NSFileProviderServicing, ChangeNotificationInte
233235

234236
actionsLock.unlock()
235237

236-
guard let argument else { return }
237-
logger.debug("Reporting sync \(argument)")
238+
guard let argument else {
239+
logger.error("State argument is nil!")
240+
return
241+
}
242+
243+
logger.debug("Reporting synchronization state.", [.name: argument])
244+
238245
let message = command + ":" + argument + "\n"
239246
socketClient?.sendMessage(message)
240247
}

shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension.swift

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ import OSLog
9090
}
9191

9292
func insertSyncAction(_ actionId: UUID) {
93+
logger.debug("Inserting synchronization action.", [.item: actionId])
94+
9395
actionsLock.lock()
9496
let oldActions = syncActions
9597
syncActions.insert(actionId)
@@ -98,6 +100,8 @@ import OSLog
98100
}
99101

100102
func insertErrorAction(_ actionId: UUID) {
103+
logger.debug("Inserting error action.", [.item: actionId])
104+
101105
actionsLock.lock()
102106
let oldActions = syncActions
103107
syncActions.remove(actionId)
@@ -107,6 +111,8 @@ import OSLog
107111
}
108112

109113
func removeSyncAction(_ actionId: UUID) {
114+
logger.debug("Removing synchronization action.", [.item: actionId])
115+
110116
actionsLock.lock()
111117
let oldActions = syncActions
112118
syncActions.remove(actionId)
@@ -274,11 +280,23 @@ import OSLog
274280
log: log
275281
)
276282

277-
if error != nil {
278-
insertErrorAction(actionId)
279-
signalEnumerator(completionHandler: { _ in })
280-
} else {
283+
if error == nil {
281284
removeSyncAction(actionId)
285+
} else {
286+
// Do not consider the exclusion of a lock file a synchronization error resulting in a misleading status report because exclusion is expected.
287+
// Though, the exclusion error code is only available starting with macOS 13, hence this logic reads a bit more cumbersome.
288+
289+
if #available(macOS 13.0, *) {
290+
if isLockFileName(itemTemplate.filename), let fileProviderError = error as? NSFileProviderError, fileProviderError.code == .excludedFromSync {
291+
removeSyncAction(actionId)
292+
} else {
293+
insertErrorAction(actionId)
294+
signalEnumerator(completionHandler: { _ in })
295+
}
296+
} else {
297+
insertErrorAction(actionId)
298+
signalEnumerator(completionHandler: { _ in })
299+
}
282300
}
283301

284302
logger.debug("Calling item creation completion handler.", [.item: item?.itemIdentifier, .name: item?.filename, .error: error])

src/gui/macOS/fileprovidersocketcontroller.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ void FileProviderSocketController::parseReceivedLine(const QString &receivedLine
9999
reportSyncState("SYNC_FINISHED");
100100
return;
101101
} else if (command == "FILE_PROVIDER_DOMAIN_SYNC_STATE_CHANGE") {
102+
qCDebug(lcFileProviderSocketController) << "Received FILE_PROVIDER_DOMAIN_SYNC_STATE_CHANGE:" << argument;
102103
reportSyncState(argument);
103104
return;
104105
}

0 commit comments

Comments
 (0)