Properly respond to errors in working set enumerateItems in FileProviderEnumerator

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-03-14 16:06:20 +01:00
Родитель 287c98f7f5
Коммит 68044891f0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: C839200C384636B0
1 изменённых файлов: 13 добавлений и 0 удалений

Просмотреть файл

@ -93,6 +93,7 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
let directoryMetadatas = dbManager.directoryMetadatas(account: ncAccount.ncKitAccount)
var allMetadatas: [NextcloudItemMetadataTable] = []
var serverError: NKError?
let dispatchGroup = DispatchGroup() // TODO: Maybe own thread?
for directoryMetadata in directoryMetadatas {
@ -106,6 +107,13 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
FileProviderEnumerator.readServerUrl(directoryMetadata.serverUrl, ncAccount: ncAccount, ncKit: ncKit) { metadatas, _, _, _, readError in
guard readError == nil else {
NSLog("Finishing enumeration of working set directory %@ with error %@", directoryMetadata.serverUrl, readError!.localizedDescription)
let nkError = NKError(error: readError!)
if nkError.isUnauthenticatedError || nkError.isCouldntConnectError {
// If it is a critical error then stop, if not then continue
serverError = nkError
}
dispatchGroup.leave()
return
}
@ -120,6 +128,11 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
}
dispatchGroup.wait()
guard serverError == nil else {
observer.finishEnumeratingWithError(serverError!.error)
return
}
}
FileProviderEnumerator.completeEnumerationObserver(observer, ncKit: self.ncKit, numPage: 1, itemMetadatas: allMetadatas)