[ios] Remove fileCoordinator wrapping from downloading starting

And add check `isUbiquitousItem` before downloading start. This method returns false when the file doesn't exist.

Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
Kiryl Kaveryn
2025-07-23 18:38:36 +04:00
committed by Konstantin Pastbin
parent 0f2353aae6
commit 31104eed4d

View File

@@ -39,18 +39,16 @@ final class SynchronizationFileWriter {
// MARK: - Read/Write/Downloading/Uploading
private func startDownloading(_ cloudMetadataItem: CloudMetadataItem, completion: WritingResultCompletionHandler) {
var coordinationError: NSError?
fileCoordinator.coordinate(writingItemAt: cloudMetadataItem.fileUrl, options: [], error: &coordinationError) { cloudItemUrl in
do {
LOG(.info, "Start downloading file: \(cloudItemUrl.path)...")
try fileManager.startDownloadingUbiquitousItem(at: cloudItemUrl)
completion(.success)
} catch {
completion(.failure(error))
LOG(.info, "Start downloading file: \(cloudMetadataItem.fileUrl.path)...")
do {
if fileManager.isUbiquitousItem(at: cloudMetadataItem.fileUrl) {
try fileManager.startDownloadingUbiquitousItem(at: cloudMetadataItem.fileUrl)
} else {
LOG(.warning, "File \(cloudMetadataItem.fileUrl.path) is not a ubiquitous item. Skipping download.")
}
}
if let coordinationError {
completion(.failure(coordinationError))
completion(.success)
} catch {
completion(.failure(error))
}
}