Bläddra i källkod

improved create folder

marinofaggiana 4 år sedan
förälder
incheckning
c3e16a0d3f

+ 1 - 1
iOSClient/Main/Create cloud/NCCreateFormUploadAssets.swift

@@ -365,7 +365,7 @@ class NCCreateFormUploadAssets: XLFormViewController, NCSelectDelegate {
             
             let autoUploadPath = NCManageDatabase.shared.getAccountAutoUploadPath(urlBase: self.appDelegate.urlBase, account: self.appDelegate.account)
             if autoUploadPath == self.serverUrl {
-                if NCNetworking.shared.createFolder(assets: self.assets, selector: NCBrandGlobal.shared.selectorUploadFile, useSubFolder: useSubFolder, account: self.appDelegate.account, urlBase: self.appDelegate.urlBase) {
+                if !NCNetworking.shared.createFolder(assets: self.assets, selector: NCBrandGlobal.shared.selectorUploadFile, useSubFolder: useSubFolder, account: self.appDelegate.account, urlBase: self.appDelegate.urlBase) {
                     NCContentPresenter.shared.messageNotification("_error_", description: "_error_createsubfolders_upload_", delay: NCBrandGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: NCBrandGlobal.shared.ErrorInternalError, forced: true)
                     return
                 }

+ 3 - 2
iOSClient/Networking/NCAutoUpload.swift

@@ -164,7 +164,7 @@ class NCAutoUpload: NSObject, CLLocationManagerDelegate {
                 guard let assets = assets else { return }
                 
                 // Create the folder for auto upload & if request the subfolders
-                if NCNetworking.shared.createFolder(assets: assets, selector: selector, useSubFolder: account.autoUploadCreateSubfolder, account: account.account, urlBase: account.urlBase) {
+                if !NCNetworking.shared.createFolder(assets: assets, selector: selector, useSubFolder: account.autoUploadCreateSubfolder, account: account.account, urlBase: account.urlBase) {
                     DispatchQueue.main.async {
                         if selector == NCBrandGlobal.shared.selectorUploadAutoUploadAll {
                             NCContentPresenter.shared.messageNotification("_error_", description: "_error_createsubfolders_upload_", delay: NCBrandGlobal.shared.dismissAfterSecond, type: .error, errorCode: NCBrandGlobal.shared.ErrorInternalError, forced: true)
@@ -255,6 +255,7 @@ class NCAutoUpload: NSObject, CLLocationManagerDelegate {
                             let fileName = (fileName as NSString).deletingPathExtension + ".mov"
                             let ocId = NSUUID().uuidString
                             let filePath = CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: fileName)!
+                            
                             CCUtility.extractLivePhotoAsset(asset, filePath: filePath) { (url) in
                                 if url != nil {
                                     let metadataForUpload = NCManageDatabase.shared.createMetadata(account: account.account, fileName: fileName, ocId: ocId, serverUrl: serverUrl, urlBase: account.urlBase, url: "", contentType: "", livePhoto: livePhoto)
@@ -272,7 +273,7 @@ class NCAutoUpload: NSObject, CLLocationManagerDelegate {
                                     }
                                 }
                                 counterLivePhoto -= 1
-                                if self.endForAssetToUpload && counterLivePhoto == 0 {
+                                if counterLivePhoto == 0 && self.endForAssetToUpload {
                                     DispatchQueue.main.async {
                                         if selector == NCBrandGlobal.shared.selectorUploadAutoUploadAll {
                                             NCManageDatabase.shared.addMetadatas(metadataFull)

+ 9 - 10
iOSClient/Networking/NCNetworking.swift

@@ -891,30 +891,29 @@ import Queuer
         let serverUrl = NCManageDatabase.shared.getAccountAutoUploadDirectory(urlBase: urlBase, account: account)
         let fileName =  NCManageDatabase.shared.getAccountAutoUploadFileName()
         let autoUploadPath = NCManageDatabase.shared.getAccountAutoUploadPath(urlBase: urlBase, account: account)
-        var error = false
+        var result = createFolderWithSemaphore(fileName: fileName, serverUrl: serverUrl, account: account, urlBase: urlBase)
         
-        error = createFolderWithSemaphore(fileName: fileName, serverUrl: serverUrl, account: account, urlBase: urlBase)
-        if useSubFolder && !error {
+        if useSubFolder && result {
             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, urlBase: urlBase)
-                if error { break }
+                result = createFolderWithSemaphore(fileName: fileName, serverUrl: serverUrl, account: account, urlBase: urlBase)
+                if !result { break }
             }
         }
         
-        return error
+        return result
     }
     
     private func createFolderWithSemaphore(fileName: String, serverUrl: String, account: String, urlBase: String) -> Bool {
-        var error = false
+        var result: Bool = false
         let semaphore = Semaphore()
         NCNetworking.shared.createFolder(fileName: fileName, serverUrl: serverUrl, account: account, urlBase: urlBase, overwrite: true) { (errorCode, errorDescription) in
-            if errorCode != 0 { error = true }
+            if errorCode == 0 { result = true }
             semaphore.continue()
         }
-        if semaphore.wait() != .success { error = true }
-        return error
+        if semaphore.wait() == .success { result = true }
+        return result
     }
     
     //MARK: - WebDav Delete