Do not delete "no longer existing files" when doing enumeration of items in FileProviderEnumerator

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-03-14 16:01:34 +01:00
parent b532b96937
commit 134e373f1b
No known key found for this signature in database
GPG key ID: C839200C384636B0

View file

@ -81,6 +81,10 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
let dbManager = NextcloudFilesDatabaseManager.shared
// If we don't have any items in the database, ignore this and go for a normal serverUrl read.
// By default we set the serverUrl to be the webdav files root when we are provided a system container id.
// However, if we do have items, we want to do a recursive scan of all the folders in the server that
// ** we have already explored ** . This is to not kill the server.
if enumeratedItemIdentifier == .workingSet && dbManager.anyItemMetadatasForAccount(ncAccount.ncKitAccount) {
if page == NSFileProviderPage.initialPageSortedByDate as NSFileProviderPage ||
page == NSFileProviderPage.initialPageSortedByName as NSFileProviderPage {
@ -102,13 +106,6 @@ 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 nkReadError = NKError(error: readError!)
if nkReadError.isNotFoundError {
NSLog("404 error means item no longer exists. Deleting metadata and reporting as deletion without error")
dbManager.deleteDirectoryAndSubdirectoriesMetadata(ocId: directoryMetadata.ocId)
}
dispatchGroup.leave()
return
}