From 714136e249cf365f920240056c29d840048365cf Mon Sep 17 00:00:00 2001 From: Kiryl Kaveryn Date: Sat, 24 Aug 2024 21:09:02 +0400 Subject: [PATCH] [ios] fix the icloud trashing bug When the file doesn't exist in the icloud dir and the manager attemps to move this file into the trash the exception is thrown and the sync is stopped. This issue was fixed by the additional file existence check. Signed-off-by: Kiryl Kaveryn --- iphone/Maps/Core/iCloud/SynchronizationFileWriter.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/iphone/Maps/Core/iCloud/SynchronizationFileWriter.swift b/iphone/Maps/Core/iCloud/SynchronizationFileWriter.swift index 94856f4413..147d537469 100644 --- a/iphone/Maps/Core/iCloud/SynchronizationFileWriter.swift +++ b/iphone/Maps/Core/iCloud/SynchronizationFileWriter.swift @@ -14,7 +14,7 @@ final class SynchronizationFileWriter { self.localDirectoryUrl = localDirectoryUrl self.cloudDirectoryUrl = cloudDirectoryUrl } - + func processEvent(_ event: OutgoingEvent, completion: @escaping WritingResultCompletionHandler) { let resultCompletion: WritingResultCompletionHandler = { result in DispatchQueue.main.sync { completion(result) } @@ -128,8 +128,13 @@ final class SynchronizationFileWriter { private func removeFromCloudContainer(_ localMetadataItem: LocalMetadataItem, completion: @escaping WritingResultCompletionHandler) { LOG(.info, "Start trashing file \(localMetadataItem.fileName)...") + let targetCloudFileUrl = localMetadataItem.relatedCloudItemUrl(to: cloudDirectoryUrl) + guard fileManager.fileExists(atPath: targetCloudFileUrl.path) else { + LOG(.warning, "File \(localMetadataItem.fileName) doesn't exist in the cloud directory and cannot be moved to the trash.") + completion(.success) + return + } do { - let targetCloudFileUrl = localMetadataItem.relatedCloudItemUrl(to: cloudDirectoryUrl) try removeDuplicatedFileFromTrashDirectoryIfNeeded(cloudDirectoryUrl: cloudDirectoryUrl, fileName: localMetadataItem.fileName) try self.fileManager.trashItem(at: targetCloudFileUrl, resultingItemURL: nil) LOG(.debug, "File \(localMetadataItem.fileName) was trashed successfully.")