Use NKError extension method in FileProviderEnumerator enumerate methods

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-03-13 14:27:17 +01:00
parent fdaf0d5aa5
commit 109258f3ce
No known key found for this signature in database
GPG key ID: C839200C384636B0

View file

@ -155,7 +155,13 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
guard readError == nil else { guard readError == nil else {
NSLog("Finishing enumeration with error") NSLog("Finishing enumeration with error")
observer.finishEnumeratingWithError(readError!)
if let nkReadError = readError as? NKError {
observer.finishEnumeratingWithError(nkReadError.toFileProviderError())
} else {
observer.finishEnumeratingWithError(readError!)
}
return return
} }
@ -236,14 +242,14 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
NSLog("Finishing enumeration of changes with error") NSLog("Finishing enumeration of changes with error")
if let nkReadError = readError as? NKError { if let nkReadError = readError as? NKError {
let nkErrorCode = nkReadError.errorCode let fpError = nkReadError.toFileProviderError()
if nkErrorCode == 404 { if nkReadError.errorCode == 404 {
NSLog("404 error means item no longer exists. Deleting metadata and reporting %@ as deletion without error", self.serverUrl) NSLog("404 error means item no longer exists. Deleting metadata and reporting %@ as deletion without error", self.serverUrl)
guard let itemMetadata = self.enumeratedItemMetadata else { guard let itemMetadata = self.enumeratedItemMetadata else {
NSLog("Invalid enumeratedItemMetadata, could not delete metadata nor report deletion") NSLog("Invalid enumeratedItemMetadata, could not delete metadata nor report deletion")
observer.finishEnumeratingWithError(NSFileProviderError(.noSuchItem)) observer.finishEnumeratingWithError(fpError)
return return
} }
@ -255,19 +261,11 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
} }
FileProviderEnumerator.completeChangesObserver(observer, anchor: anchor, ncKit: self.ncKit, newMetadatas: nil, updatedMetadatas: nil, deletedMetadatas: [itemMetadata]) FileProviderEnumerator.completeChangesObserver(observer, anchor: anchor, ncKit: self.ncKit, newMetadatas: nil, updatedMetadatas: nil, deletedMetadatas: [itemMetadata])
} else if nkErrorCode == -9999 || nkErrorCode == -1001 || nkErrorCode == -1004 || nkErrorCode == -1005 || nkErrorCode == -1009 || nkErrorCode == -1012 || nkErrorCode == -1200 || nkErrorCode == -1202 || nkErrorCode == 500 || nkErrorCode == 503 || nkErrorCode == 200 {
// Provide something the file provider can do something with
observer.finishEnumeratingWithError(NSFileProviderError(.serverUnreachable))
return return
} else if nkErrorCode == -1013 {
observer.finishEnumeratingWithError(NSFileProviderError(.notAuthenticated))
return
} else if nkErrorCode == 507 {
observer.finishEnumeratingWithError(NSFileProviderError(.insufficientQuota))
return
} else {
observer.finishEnumeratingWithError(NSFileProviderError(.cannotSynchronize))
} }
observer.finishEnumeratingWithError(fpError)
return
} }
observer.finishEnumeratingWithError(readError!) observer.finishEnumeratingWithError(readError!)