From 9353a68ea8071d09f0f5313d3de5ca7f9841e8bd Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 11 Dec 2024 16:09:32 +0800 Subject: [PATCH] Handle post-trash-restore case where scanned restore path returns different file When restoring from trash to a location that already has a file with the same name, this may happen Signed-off-by: Claudio Cambra --- .../NextcloudFileProviderKit/Item/Item+Modify.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sources/NextcloudFileProviderKit/Item/Item+Modify.swift b/Sources/NextcloudFileProviderKit/Item/Item+Modify.swift index 891b1e2d..f0b4bde7 100644 --- a/Sources/NextcloudFileProviderKit/Item/Item+Modify.swift +++ b/Sources/NextcloudFileProviderKit/Item/Item+Modify.swift @@ -678,6 +678,17 @@ public extension Item { return (modifiedItem, enumerateError.fileProviderError) } + guard target.ocId == modifiedItem.itemIdentifier.rawValue else { + Self.logger.error( + """ + Restored item \(originalLocation, privacy: .public) + does not match \(modifiedItem.filename, privacy: .public) + (it is likely that when restoring from the trash, there was another identical item). + """ + ) // TODO: Be more permissive of this and just rescan remote state + return (modifiedItem, NSFileProviderError(.cannotSynchronize)) + } + let restoredItemMetadata = ItemMetadata.fromNKFile(target, account: account) guard let parentItemIdentifier = dbManager.parentItemIdentifierFromMetadata( restoredItemMetadata