diff --git a/iOSClient/Data/NCManageDatabase+Metadata+Session.swift b/iOSClient/Data/NCManageDatabase+Metadata+Session.swift index 311e4edc59..924d0afd80 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata+Session.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata+Session.swift @@ -175,4 +175,16 @@ extension NCManageDatabase { return nil } } + + func getMetadata(from url: URL?, sessionTaskIdentifier: Int) -> tableMetadata? { + guard let url, + var serverUrl = url.deletingLastPathComponent().absoluteString.removingPercentEncoding + else { return nil } + let fileName = url.lastPathComponent + + if serverUrl.hasSuffix("/") { + serverUrl = String(serverUrl.dropLast()) + } + return NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "serverUrl == %@ AND fileName == %@ AND sessionTaskIdentifier == %d", serverUrl, fileName, sessionTaskIdentifier)) + } } diff --git a/iOSClient/Data/NCManageDatabase+Metadata.swift b/iOSClient/Data/NCManageDatabase+Metadata.swift index 60ad8dbd22..606eb29819 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata.swift @@ -1147,16 +1147,4 @@ extension NCManageDatabase { return nil } - - func getMetadata(from url: URL?) -> tableMetadata? { - guard let url, - var serverUrl = url.deletingLastPathComponent().absoluteString.removingPercentEncoding - else { return nil } - let fileName = url.lastPathComponent - - if serverUrl.hasSuffix("/") { - serverUrl = String(serverUrl.dropLast()) - } - return NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "serverUrl == %@ AND fileName == %@", serverUrl, fileName)) - } } diff --git a/iOSClient/Networking/NCNetworking+Download.swift b/iOSClient/Networking/NCNetworking+Download.swift index 4f10cb4676..10dcbb7985 100644 --- a/iOSClient/Networking/NCNetworking+Download.swift +++ b/iOSClient/Networking/NCNetworking+Download.swift @@ -192,7 +192,7 @@ extension NCNetworking { DispatchQueue.global().async { guard let url = task.currentRequest?.url, - let metadata = NCManageDatabase.shared.getMetadata(from: url) else { return } + let metadata = NCManageDatabase.shared.getMetadata(from: url, sessionTaskIdentifier: task.taskIdentifier) else { return } self.downloadMetadataInBackground.removeValue(forKey: FileNameServerUrl(fileName: fileName, serverUrl: serverUrl)) diff --git a/iOSClient/Networking/NCNetworking+Upload.swift b/iOSClient/Networking/NCNetworking+Upload.swift index ec83cd56a1..a645e8d1b0 100644 --- a/iOSClient/Networking/NCNetworking+Upload.swift +++ b/iOSClient/Networking/NCNetworking+Upload.swift @@ -313,7 +313,7 @@ extension NCNetworking { task: URLSessionTask, error: NKError) { guard let url = task.currentRequest?.url, - let metadata = NCManageDatabase.shared.getMetadata(from: url) else { return } + let metadata = NCManageDatabase.shared.getMetadata(from: url, sessionTaskIdentifier: task.taskIdentifier) else { return } uploadComplete(metadata: metadata, ocId: ocId, etag: etag, date: date, size: size, error: error) }