Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/ios.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarinofaggiana <ios@nextcloud.com>2022-08-04 12:06:28 +0300
committermarinofaggiana <ios@nextcloud.com>2022-08-04 12:06:28 +0300
commit462cad06f14936135845775a8353eecd7a6c08c8 (patch)
treecb14a74cb54492eda5a8b8669cabc83677e802fa /iOSClient
parente48be2833cec1829b94476dd14d89f132d297bd2 (diff)
add ThreadSafeDictionary
Signed-off-by: marinofaggiana <ios@nextcloud.com>
Diffstat (limited to 'iOSClient')
-rw-r--r--iOSClient/AppDelegate.swift6
-rw-r--r--iOSClient/Data/NCDataSource.swift4
-rw-r--r--iOSClient/Data/NCManageDatabase+Metadata.swift2
-rw-r--r--iOSClient/Main/Create cloud/NCCreateFormUploadConflict.swift2
-rw-r--r--iOSClient/Networking/NCNetworking.swift11
-rw-r--r--iOSClient/Networking/NCNetworkingChunkedUpload.swift2
-rw-r--r--iOSClient/Networking/NCNetworkingE2EE.swift2
-rw-r--r--iOSClient/Utility/ThreadSafeDictionary.swift65
8 files changed, 80 insertions, 14 deletions
diff --git a/iOSClient/AppDelegate.swift b/iOSClient/AppDelegate.swift
index fc1380fe7..95409596b 100644
--- a/iOSClient/AppDelegate.swift
+++ b/iOSClient/AppDelegate.swift
@@ -49,9 +49,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
var mainTabBar: NCMainTabBar?
var activeMetadata: tableMetadata?
- var listFilesVC: [String: NCFiles] = [:]
- var listFavoriteVC: [String: NCFavorite] = [:]
- var listOfflineVC: [String: NCOffline] = [:]
+ let listFilesVC = ThreadSafeDictionary<String,NCFiles>()
+ let listFavoriteVC = ThreadSafeDictionary<String,NCFavorite>()
+ let listOfflineVC = ThreadSafeDictionary<String,NCOffline>()
var disableSharesView: Bool = false
var documentPickerViewController: NCDocumentPickerViewController?
diff --git a/iOSClient/Data/NCDataSource.swift b/iOSClient/Data/NCDataSource.swift
index a1eda42c8..6922093a3 100644
--- a/iOSClient/Data/NCDataSource.swift
+++ b/iOSClient/Data/NCDataSource.swift
@@ -125,7 +125,7 @@ class NCDataSource: NSObject {
// Unified search
if let providers = self.providers, !providers.isEmpty {
- var sectionsDictionary: [String:Int] = [:]
+ let sectionsDictionary = ThreadSafeDictionary<String,Int>()
for section in self.sectionsValue {
if let provider = providers.filter({ $0.name.lowercased() == section.lowercased()}).first {
sectionsDictionary[section] = provider.order
@@ -434,7 +434,7 @@ class NCMetadataForSection: NSObject {
public var numDirectory: Int = 0
public var numFile: Int = 0
public var totalSize: Int64 = 0
- public var metadataShare: [String: tableShare] = [:]
+ public let metadataShare = ThreadSafeDictionary<String,tableShare>()
public var metadataOffLine: [String] = []
public var directories: [tableDirectory]?
diff --git a/iOSClient/Data/NCManageDatabase+Metadata.swift b/iOSClient/Data/NCManageDatabase+Metadata.swift
index 589fda7a2..3ec6cad5d 100644
--- a/iOSClient/Data/NCManageDatabase+Metadata.swift
+++ b/iOSClient/Data/NCManageDatabase+Metadata.swift
@@ -132,7 +132,7 @@ extension NCManageDatabase {
var counter: Int = 0
var isEncrypted: Bool = false
- var listServerUrl: [String: Bool] = [:]
+ let listServerUrl = ThreadSafeDictionary<String,Bool>()
var metadataFolder = tableMetadata()
var metadataFolders: [tableMetadata] = []
diff --git a/iOSClient/Main/Create cloud/NCCreateFormUploadConflict.swift b/iOSClient/Main/Create cloud/NCCreateFormUploadConflict.swift
index 9f13cc255..67d42110f 100644
--- a/iOSClient/Main/Create cloud/NCCreateFormUploadConflict.swift
+++ b/iOSClient/Main/Create cloud/NCCreateFormUploadConflict.swift
@@ -60,7 +60,7 @@ extension NCCreateFormUploadConflictDelegate {
var metadatasConflictNewFiles: [String] = []
var metadatasConflictAlreadyExistingFiles: [String] = []
- var fileNamesPath: [String: String] = [:]
+ let fileNamesPath = ThreadSafeDictionary<String,String>()
var blurView: UIVisualEffectView!
// MARK: - View Life Cycle
diff --git a/iOSClient/Networking/NCNetworking.swift b/iOSClient/Networking/NCNetworking.swift
index acc60d2c9..bb1394aa1 100644
--- a/iOSClient/Networking/NCNetworking.swift
+++ b/iOSClient/Networking/NCNetworking.swift
@@ -45,9 +45,9 @@ import Photos
var lastReachability: Bool = true
var networkReachability: NCCommunicationCommon.typeReachability?
- var downloadRequest: [String: DownloadRequest] = [:]
- var uploadRequest: [String: UploadRequest] = [:]
- var uploadMetadataInBackground: [String: tableMetadata] = [:]
+ let downloadRequest = ThreadSafeDictionary<String,DownloadRequest>()
+ let uploadRequest = ThreadSafeDictionary<String,UploadRequest>()
+ let uploadMetadataInBackground = ThreadSafeDictionary<String,tableMetadata>()
@objc public let sessionMaximumConnectionsPerHost = 5
@objc public let sessionIdentifierBackground: String = "com.nextcloud.session.upload.background"
@@ -327,6 +327,7 @@ import Photos
NCCommunication.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, queue: NCCommunicationCommon.shared.backgroundQueue, requestHandler: { request in
self.downloadRequest[fileNameLocalPath] = request
+ self.downloadRequest.removeValue(forKey: fileNameLocalPath)
NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, status: NCGlobal.shared.metadataStatusDownloading)
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDownloadStartFile, userInfo: ["ocId":metadata.ocId, "serverUrl": metadata.serverUrl, "account": metadata.account])
@@ -448,7 +449,7 @@ import Photos
}) { _, ocId, etag, date, size, _, _, errorCode, errorDescription in
- self.uploadRequest[fileNameLocalPath] = nil
+ self.uploadRequest.removeValue(forKey: fileNameLocalPath)
if let uploadTask = uploadTask {
self.uploadComplete(fileName: metadata.fileName, serverUrl: metadata.serverUrl, ocId: ocId, etag: etag, date: date, size: size, description: description, task: uploadTask, errorCode: errorCode, errorDescription: errorDescription)
}
@@ -556,7 +557,7 @@ import Photos
}
}
- self.uploadMetadataInBackground[fileName + serverUrl] = nil
+ self.uploadMetadataInBackground.removeValue(forKey: fileName + serverUrl)
self.delegate?.uploadComplete?(fileName: fileName, serverUrl: serverUrl, ocId: ocId, etag: etag, date: date, size: size, description: description, task: task, errorCode: errorCode, errorDescription: errorDescription)
}
}
diff --git a/iOSClient/Networking/NCNetworkingChunkedUpload.swift b/iOSClient/Networking/NCNetworkingChunkedUpload.swift
index c9a1fef3a..6aa4627ba 100644
--- a/iOSClient/Networking/NCNetworkingChunkedUpload.swift
+++ b/iOSClient/Networking/NCNetworkingChunkedUpload.swift
@@ -112,7 +112,7 @@ extension NCNetworking {
}) { _, _, _, _, _, _, _, errorCode, errorDescription in
- self.uploadRequest[fileNameLocalPath] = nil
+ self.uploadRequest.removeValue(forKey: fileNameLocalPath)
uploadErrorCode = errorCode
uploadErrorDescription = errorDescription
semaphore.continue()
diff --git a/iOSClient/Networking/NCNetworkingE2EE.swift b/iOSClient/Networking/NCNetworkingE2EE.swift
index b8e86351b..60fe91f37 100644
--- a/iOSClient/Networking/NCNetworkingE2EE.swift
+++ b/iOSClient/Networking/NCNetworkingE2EE.swift
@@ -287,7 +287,7 @@ import Alamofire
}) { account, ocId, etag, date, _, _, error, errorCode, errorDescription in
- NCNetworking.shared.uploadRequest[fileNameLocalPath] = nil
+ NCNetworking.shared.uploadRequest.removeValue(forKey: fileNameLocalPath)
if let metadata = NCManageDatabase.shared.getMetadataFromOcId(metadata.ocId) {
if error?.isExplicitlyCancelledError ?? false {
diff --git a/iOSClient/Utility/ThreadSafeDictionary.swift b/iOSClient/Utility/ThreadSafeDictionary.swift
new file mode 100644
index 000000000..c06e0c476
--- /dev/null
+++ b/iOSClient/Utility/ThreadSafeDictionary.swift
@@ -0,0 +1,65 @@
+//
+// ThreadSafeDictionary.swift
+//
+// Created by Shashank on 29/10/20.
+//
+
+class ThreadSafeDictionary<V: Hashable, T>: Collection {
+
+ private var dictionary: [V: T]
+ private let concurrentQueue = DispatchQueue(label: "Dictionary Barrier Queue", attributes: .concurrent)
+
+ var startIndex: Dictionary<V, T>.Index {
+ self.concurrentQueue.sync {
+ return self.dictionary.startIndex
+ }
+ }
+
+ var endIndex: Dictionary<V, T>.Index {
+ self.concurrentQueue.sync {
+ return self.dictionary.endIndex
+ }
+ }
+
+ init(dict: [V: T] = [V: T]()) {
+ self.dictionary = dict
+ }
+
+ func index(after i: Dictionary<V, T>.Index) -> Dictionary<V, T>.Index {
+ self.concurrentQueue.sync {
+ return self.dictionary.index(after: i)
+ }
+ }
+
+ subscript(key: V) -> T? {
+ get {
+ self.concurrentQueue.sync {
+ return self.dictionary[key]
+ }
+ }
+ set(newValue) {
+ self.concurrentQueue.async(flags: .barrier) {[weak self] in
+ self?.dictionary[key] = newValue
+ }
+ }
+ }
+
+ subscript(index: Dictionary<V, T>.Index) -> Dictionary<V, T>.Element {
+ self.concurrentQueue.sync {
+ return self.dictionary[index]
+ }
+ }
+
+ func removeValue(forKey key: V) {
+ self.concurrentQueue.async(flags: .barrier) {[weak self] in
+ self?.dictionary.removeValue(forKey: key)
+ }
+ }
+
+ func removeAll() {
+ self.concurrentQueue.async(flags: .barrier) {[weak self] in
+ self?.dictionary.removeAll()
+ }
+ }
+
+}