From c1a5bae35176516bdf047f8df9ac6746d9a753a2 Mon Sep 17 00:00:00 2001 From: Amir Abbas Date: Fri, 4 May 2018 00:42:25 +0430 Subject: [PATCH] Minor performance improvement on iCloud file progress monitor --- Sources/CloudFileProvider.swift | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/Sources/CloudFileProvider.swift b/Sources/CloudFileProvider.swift index 5c72f9e..c61b3e5 100644 --- a/Sources/CloudFileProvider.swift +++ b/Sources/CloudFileProvider.swift @@ -584,6 +584,23 @@ open class CloudFileProvider: LocalFileProvider, FileProviderSharing { } fileprivate func monitorFile(path: String, operation: FileOperationType, progress: Progress?) { + var isDownloadingOperation: Bool + let isUploadingOperation: Bool + switch operation { + case .copy(_, destination: let dest) where dest.hasPrefix("file://"), .move(_, destination: let dest) where dest.hasPrefix("file://"): + fallthrough + case .fetch: + isDownloadingOperation = true + isUploadingOperation = false + case .copy(source: let source, _) where source.hasPrefix("file://"), .move(source: let source, _) where source.hasPrefix("file://"): + fallthrough + case .modify, .create: + isDownloadingOperation = false + isUploadingOperation = true + default: + return + } + let pathURL = self.url(of: path).standardizedFileURL let query = NSMetadataQuery() query.predicate = NSPredicate(format: "(%K LIKE[CD] %@)", NSMetadataItemPathKey, pathURL.path) @@ -594,22 +611,6 @@ open class CloudFileProvider: LocalFileProvider, FileProviderSharing { NSMetadataItemFSSizeKey] query.searchScopes = [self.scope.rawValue] - var isDownloadingOperation = false - var isUploadingOperation = false - - switch operation { - case .fetch: - isDownloadingOperation = true - case .modify, .create: - isUploadingOperation = true - case .copy(_, destination: let dest) where dest.hasPrefix("file://"), .move(_, destination: let dest) where dest.hasPrefix("file://"): - isDownloadingOperation = true - case .copy(source: let source, _) where source.hasPrefix("file://"), .move(source: let source, _) where source.hasPrefix("file://"): - isDownloadingOperation = true - default: - break - } - var observer: NSObjectProtocol? observer = NotificationCenter.default.addObserver(forName: .NSMetadataQueryDidUpdate, object: query, queue: .main) { [weak self] (notification) in guard let items = notification.userInfo?[NSMetadataQueryUpdateChangedItemsKey] as? NSArray,