marinofaggiana пре 4 година
родитељ
комит
cba81fe090

+ 0 - 3
iOSClient/AutoUpload/NCAutoUpload.h

@@ -34,9 +34,6 @@
 - (void)initStateAutoUpload;
 - (BOOL)checkIfLocationIsEnabled;
 - (void)setupAutoUploadFull;
-
-- (void)createAutoUploadFolderWithSubFolder:(BOOL)useSubFolder assets:(PHFetchResult *)assets selector:(NSString *)selector;
-
 - (void)alignPhotoLibrary;
 
 @end

+ 7 - 21
iOSClient/AutoUpload/NCAutoUpload.m

@@ -370,7 +370,13 @@
     });
     
     // Create the folder for auto upload & if request the subfolders
-    [[NCAutoUpload sharedInstance] createAutoUploadFolderWithSubFolder:tableAccount.autoUploadCreateSubfolder assets:newAssetToUpload selector:selector];
+    if ([[NCNetworking shared] createFoloderWithAssets:newAssetToUpload selector:selector useSubFolder:tableAccount.autoUploadCreateSubfolder account:appDelegate.activeAccount url:appDelegate.activeUrl]) {
+        [[NCContentPresenter shared] messageNotification:@"_error_" description:@"_error_createsubfolders_upload_" delay:k_dismissAfterSecond type:messageTypeError errorCode:k_CCErrorInternalError forced:true];
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [_hud hideHud];
+        });
+        return;
+    }
     
     for (PHAsset *asset in newAssetToUpload) {
         
@@ -484,26 +490,6 @@
     }
 }
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== Create Folder SubFolder Auto Upload Folder Photos/Videos ====
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)createAutoUploadFolderWithSubFolder:(BOOL)useSubFolder assets:(PHFetchResult *)assets selector:(NSString *)selector
-{
-    NSString *serverUrl = [[NCManageDatabase sharedInstance] getAccountAutoUploadDirectory:appDelegate.activeUrl];
-    NSString *filename = [[NCManageDatabase sharedInstance] getAccountAutoUploadFileName];
-    NSString *autoUploadPath = [[NCManageDatabase sharedInstance] getAccountAutoUploadPath:appDelegate.activeUrl];
-    
-    [[NCOperationQueue shared] createFolderWithFilename:filename serverUrl:serverUrl account:appDelegate.activeAccount url:appDelegate.activeUrl overwrite:true];
-    if (useSubFolder) {
-        for (NSString *dateSubFolder in [CCUtility createNameSubFolder:assets]) {
-            NSString *filename = dateSubFolder.lastPathComponent;
-            NSString *serverUrl = [NSString stringWithFormat:@"%@/%@", autoUploadPath, dateSubFolder].stringByDeletingLastPathComponent;
-            [[NCOperationQueue shared] createFolderWithFilename:filename serverUrl:serverUrl account:appDelegate.activeAccount url:appDelegate.activeUrl overwrite:true];
-        }
-    }
-}
-
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== get Camera Roll new Asset ====
 #pragma --------------------------------------------------------------------------------------------

+ 4 - 1
iOSClient/Main/CCMain.m

@@ -986,7 +986,10 @@
 
         // if request create the folder for Auto Upload & the subfolders
         if ([autoUploadPath isEqualToString:serverUrl]) {
-            [[NCAutoUpload sharedInstance] createAutoUploadFolderWithSubFolder:useSubFolder assets:(PHFetchResult *)assets selector:selectorUploadFile];
+            if ([[NCNetworking shared] createFoloderWithAssets:(PHFetchResult *)assets selector:selectorUploadFile useSubFolder:useSubFolder account:appDelegate.activeAccount url:appDelegate.activeUrl]) {
+                [[NCContentPresenter shared] messageNotification:@"_error_" description:@"_error_createsubfolders_upload_" delay:k_dismissAfterSecond type:messageTypeError errorCode:k_CCErrorInternalError forced:true];
+                return;
+            }
         }
         
         dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {

+ 32 - 0
iOSClient/Networking/NCNetworking.swift

@@ -25,6 +25,7 @@ import Foundation
 import OpenSSL
 import NCCommunication
 import Alamofire
+import Queuer
 
 @objc public protocol NCNetworkingDelegate {
     @objc optional func downloadProgress(_ progress: Double, totalBytes: Int64, totalBytesExpected: Int64, fileName: String, serverUrl: String, session: URLSession, task: URLSessionTask)
@@ -649,7 +650,38 @@ import Alamofire
             }
         }
     }
+    
+    @objc func createFoloder(assets: PHFetchResult<AnyObject>, selector: String, useSubFolder: Bool, account: String, url: String) -> Bool {
+        
+        let serverUrl = NCManageDatabase.sharedInstance.getAccountAutoUploadDirectory(url)
+        let fileName =  NCManageDatabase.sharedInstance.getAccountAutoUploadFileName()
+        let autoUploadPath = NCManageDatabase.sharedInstance.getAccountAutoUploadPath(url)
+        var error = false
+        
+        error = createFolderWithSemaphore(fileName: fileName, serverUrl: serverUrl, account: account, url: url)
+        if useSubFolder && !error {
+            for dateSubFolder in CCUtility.createNameSubFolder(assets) {
+                let fileName = (dateSubFolder as! NSString).lastPathComponent
+                let serverUrl = ((autoUploadPath + "/" + (dateSubFolder as! String)) as NSString).deletingLastPathComponent
+                error = createFolderWithSemaphore(fileName: fileName, serverUrl: serverUrl, account: account, url: url)
+                if error { break }
+            }
+        }
         
+        return error
+    }
+    
+    private func createFolderWithSemaphore(fileName: String, serverUrl: String, account: String, url: String) -> Bool {
+        var error = false
+        let semaphore = Semaphore()
+        NCNetworking.shared.createFolder(fileName: fileName, serverUrl: serverUrl, account: account, url: url, overwrite: true) { (errorCode, errorDescription) in
+            if errorCode != 0 { error = true }
+            semaphore.continue()
+        }
+        if semaphore.wait() != .success { error = true }
+        return error
+    }
+    
     //MARK: - WebDav Delete
 
     @objc func deleteMetadata(_ metadata: tableMetadata, account: String, url: String, completion: @escaping (_ errorCode: Int, _ errorDescription: String)->()) {

+ 0 - 40
iOSClient/Networking/NCOperationQueue.swift

@@ -34,7 +34,6 @@ import NCCommunication
     
     private var downloadQueue = Queuer(name: "downloadQueue", maxConcurrentOperationCount: 5, qualityOfService: .default)
     private let synchronizationQueue = Queuer(name: "synchronizationQueue", maxConcurrentOperationCount: 1, qualityOfService: .default)
-    private let createFolderQueue = Queuer(name: "createFolderQueue", maxConcurrentOperationCount: 1, qualityOfService: .default)
     private let downloadThumbnailQueue = Queuer(name: "downloadThumbnailQueue", maxConcurrentOperationCount: 10, qualityOfService: .default)
     private let readFileForMediaQueue = Queuer(name: "readFileForMediaQueue", maxConcurrentOperationCount: 10, qualityOfService: .default)
 
@@ -43,7 +42,6 @@ import NCCommunication
     @objc func cancelAllQueue() {
         downloadCancelAll()
         synchronizationCancelAll()
-        createFolderCancelAll()
         downloadThumbnailCancelAll()
         readFileForMediaCancelAll()
     }
@@ -69,15 +67,6 @@ import NCCommunication
         synchronizationQueue.cancelAll()
     }
     
-    // Create Folder
-    
-    @objc func createFolder(filename: String, serverUrl: String, account: String, url: String, overwrite: Bool) {
-        createFolderQueue.addOperation(NCOperationCreaterFolder.init(filename: filename, serverUrl: serverUrl, account: account, url: url, overwrite: overwrite))
-    }
-    @objc func createFolderCancelAll() {
-        createFolderQueue.cancelAll()
-    }
-    
     // Download Thumbnail
     
     @objc func downloadThumbnail(metadata: tableMetadata, activeUrl: String, view: Any, indexPath: IndexPath) {
@@ -222,35 +211,6 @@ class NCOperationSynchronization: ConcurrentOperation {
 
 //MARK: -
 
-class NCOperationCreaterFolder: ConcurrentOperation {
-   
-    private var filename: String
-    private var serverUrl: String
-    private var account: String
-    private var url: String
-    private var overwrite: Bool
-
-    init(filename: String, serverUrl: String, account: String, url: String, overwrite: Bool) {
-        self.filename = filename
-        self.serverUrl = serverUrl
-        self.account = account
-        self.url = url
-        self.overwrite = overwrite
-    }
-    
-    override func start() {
-        if isCancelled {
-            self.finish()
-        } else {
-            NCNetworking.shared.createFolder(fileName: filename, serverUrl: serverUrl, account: account, url: url, overwrite: overwrite) { (errorCode, errorDescription) in
-                self.finish()
-            }
-        }
-    }
-}
-
-//MARK: -
-
 class NCOperationDownloadThumbnail: ConcurrentOperation {
    
     var metadata: tableMetadata