Use ocIds for directory metadata deletion, prevent deletion if no such directory found in NextcloudFilesDatabaseManager

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-03-09 16:47:27 +01:00
Родитель 65ed3ad846
Коммит 25a09e1704
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: C839200C384636B0
2 изменённых файлов: 11 добавлений и 6 удалений

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

@ -550,8 +550,8 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm
let serverUrl = itemMetadata.serverUrl
if itemMetadata.directory && dbManager.directoryMetadata(ocId: ocId) != nil {
dbManager.deleteDirectoryAndSubdirectoriesMetadata(account: account, serverUrl: serverUrl)
if itemMetadata.directory {
dbManager.deleteDirectoryAndSubdirectoriesMetadata(ocId: ocId)
}
if dbManager.localFileMetadataFromOcId(ocId) != nil {

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

@ -333,7 +333,7 @@ class NextcloudFilesDatabaseManager : NSObject {
"""
, metadataToDelete.ocId, metadataToDelete.serverUrl, metadataToDelete.etag)
self.deleteDirectoryAndSubdirectoriesMetadata(account: metadataToDelete.account, serverUrl: metadataToDelete.serverUrl)
self.deleteDirectoryAndSubdirectoriesMetadata(ocId: metadataToDelete.ocId)
}
}
@ -450,9 +450,14 @@ class NextcloudFilesDatabaseManager : NSObject {
}
// Deletes all metadatas related to the info of the directory provided
func deleteDirectoryAndSubdirectoriesMetadata(account: String, serverUrl: String) {
func deleteDirectoryAndSubdirectoriesMetadata(ocId: String) {
let database = ncDatabase()
let results = database.objects(NextcloudDirectoryMetadataTable.self).filter("account == %@ AND serverUrl BEGINSWITH %@", account, serverUrl)
guard let directoryMetadata = database.objects(NextcloudDirectoryMetadataTable.self).filter("ocId == %@", ocId).first else {
NSLog("Could not find directory metadata for ocId %@. Not proceeding with deletion", ocId)
return
}
let results = database.objects(NextcloudDirectoryMetadataTable.self).filter("account == %@ AND serverUrl BEGINSWITH %@", directoryMetadata.account, directoryMetadata.serverUrl)
for result in results {
deleteItemMetadata(ocId: result.ocId)
@ -464,7 +469,7 @@ class NextcloudFilesDatabaseManager : NSObject {
database.delete(results)
}
} catch let error {
NSLog("Could not relete directory metadata with serverUrl: %@, received error: %@", serverUrl, error.localizedDescription)
NSLog("Could not delete directory metadata with ocId: %@ and serverUrl: %@, received error: %@", directoryMetadata.ocId, directoryMetadata.serverUrl, error.localizedDescription)
}
}