Skip to content

Commit

Permalink
Update service
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanov91 committed Jun 8, 2023
1 parent 21ca8a6 commit 26c2389
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
--swiftversion 5.8
--swiftversion 5.7
--disable preferKeyPath
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.8
// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
21 changes: 8 additions & 13 deletions Sources/OversizeFileManagerService/FileManagerSyncService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,9 @@ public class FileManagerSyncService {
}

extension FileManagerSyncService: FileManagerSyncServiceProtocol {
private func downloadFromCloud(url: URL?) async -> Result<Bool, AppError> {
do {
if let url, url.fileExists() == false {
try FileManager.default.startDownloadingUbiquitousItem(at: url)
return .success(true)
} else {
return .failure(.cloudDocuments(type: .fetchItems))
}
} catch {
return .failure(.cloudDocuments(type: .fetchItems))
private func downloadFromCloud(url: URL?) async throws {
if let url, url.fileExists() == false {
try FileManager.default.startDownloadingUbiquitousItem(at: url)
}
}

Expand All @@ -53,9 +46,11 @@ extension FileManagerSyncService: FileManagerSyncServiceProtocol {
}
if location == .iCloud {
let url = await cloudDocumentsService.giveURL(folder: folder, file: file ?? "file", containerId: nil)
let _ = await downloadFromCloud(url: url)
guard let url else { return .failure(.cloudDocuments(type: .fetchItems)) }
return .success(url)
do {
try await downloadFromCloud(url: url)
} catch {
return .failure(.cloudDocuments(type: .fetchItems))
}
} else {
let url = await fileManagerService.giveURL(folder: folder, file: file ?? "file")
if url?.fileExists() ?? false {
Expand Down

0 comments on commit 26c2389

Please sign in to comment.