Marino Faggiana 6 anos atrás
pai
commit
4cb3cb4235

+ 36 - 34
File Provider Extension/FileProviderEnumerator.swift

@@ -144,53 +144,55 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
             }
             
             let ocNetworking = OCnetworking.init(delegate: nil, metadataNet: nil, withUser: nil, withUserID: nil, withPassword: nil, withUrl: nil)
-            ocNetworking?.readFile(fileName, serverUrl: serverUrlForFileName, account: providerData.account, success: { (account, metadata) in
+            ocNetworking?.readFile(withAccount: providerData.account, serverUrl: serverUrlForFileName, fileName: fileName, completion: { (account, metadata, message, errorCode) in
                 
-                if self.providerData.listServerUrlEtag[serverUrl] == nil || self.providerData.listServerUrlEtag[serverUrl] != metadata!.etag || metadatasFromDB == nil {
+                if errorCode == 0 && account == self.providerData.account {
                     
-                    ocNetworking?.readFolder(withAccount: self.providerData.account, serverUrl: serverUrl, depth: "1", completion: { (account, metadatas, metadataFolder, message, errorCode) in
+                    if self.providerData.listServerUrlEtag[serverUrl] == nil || self.providerData.listServerUrlEtag[serverUrl] != metadata!.etag || metadatasFromDB == nil {
                         
-                        if errorCode == 0 && account == self.providerData.account {
+                        ocNetworking?.readFolder(withAccount: self.providerData.account, serverUrl: serverUrl, depth: "1", completion: { (account, metadatas, metadataFolder, message, errorCode) in
                             
-                            if metadataFolder != nil {
-                                // Update directory etag
-                                NCManageDatabase.sharedInstance.setDirectory(serverUrl: serverUrl, serverUrlTo: nil, etag: metadataFolder!.etag, fileID: metadataFolder!.fileID, encrypted: metadataFolder!.e2eEncrypted, account: self.providerData.account)
-                                // Save etag for this serverUrl
-                                self.providerData.listServerUrlEtag[serverUrl] = metadataFolder!.etag
-                            }
-                            
-                            if metadatas != nil {
+                            if errorCode == 0 && account == self.providerData.account {
                                 
-                                NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND (status == %d OR status == %d)", self.providerData.account, serverUrl, k_metadataStatusNormal, k_metadataStatusHide))
+                                if metadataFolder != nil {
+                                    // Update directory etag
+                                    NCManageDatabase.sharedInstance.setDirectory(serverUrl: serverUrl, serverUrlTo: nil, etag: metadataFolder!.etag, fileID: metadataFolder!.fileID, encrypted: metadataFolder!.e2eEncrypted, account: self.providerData.account)
+                                    // Save etag for this serverUrl
+                                    self.providerData.listServerUrlEtag[serverUrl] = metadataFolder!.etag
+                                }
                                 
-                                NCManageDatabase.sharedInstance.setDateReadDirectory(serverUrl: serverUrl, account: self.providerData.account)
+                                if metadatas != nil {
+                                    
+                                    NCManageDatabase.sharedInstance.deleteMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND (status == %d OR status == %d)", self.providerData.account, serverUrl, k_metadataStatusNormal, k_metadataStatusHide))
+                                    
+                                    NCManageDatabase.sharedInstance.setDateReadDirectory(serverUrl: serverUrl, account: self.providerData.account)
+                                    
+                                    let metadatasInDownload = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND (status == %d OR status == %d OR status == %d OR status == %d)", self.providerData.account, serverUrl, k_metadataStatusWaitDownload, k_metadataStatusInDownload, k_metadataStatusDownloading, k_metadataStatusDownloadError), sorted: nil, ascending: false)
+                                    
+                                    _ = NCManageDatabase.sharedInstance.addMetadatas(metadatas as! [tableMetadata])
+                                    if metadatasInDownload != nil {
+                                        _ = NCManageDatabase.sharedInstance.addMetadatas(metadatasInDownload!)
+                                    }
+                                }
                                 
-                                let metadatasInDownload = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND (status == %d OR status == %d OR status == %d OR status == %d)", self.providerData.account, serverUrl, k_metadataStatusWaitDownload, k_metadataStatusInDownload, k_metadataStatusDownloading, k_metadataStatusDownloadError), sorted: nil, ascending: false)
+                                metadatasFromDB = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", self.providerData.account, serverUrl), sorted: "fileName", ascending: true)
                                 
-                                _ = NCManageDatabase.sharedInstance.addMetadatas(metadatas as! [tableMetadata])
-                                if metadatasInDownload != nil {
-                                    _ = NCManageDatabase.sharedInstance.addMetadatas(metadatasInDownload!)
-                                }
+                                self.selectFirstPageItems(metadatasFromDB, observer: observer)
+                                
+                            } else if errorCode != 0 {
+                                
+                                self.selectFirstPageItems(metadatasFromDB, observer: observer)
                             }
-                            
-                            metadatasFromDB = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", self.providerData.account, serverUrl), sorted: "fileName", ascending: true)
-                            
-                            self.selectFirstPageItems(metadatasFromDB, observer: observer)
-                            
-                        } else if errorCode != 0 {
-                            
-                            self.selectFirstPageItems(metadatasFromDB, observer: observer)
-                        }
-                    })
+                        })
+                        
+                    } else {
+                        
+                        self.selectFirstPageItems(metadatasFromDB, observer: observer)
+                    }
                     
                 } else {
-                    
                     self.selectFirstPageItems(metadatasFromDB, observer: observer)
                 }
-                
-            }, failure: { (account, message, errorCode) in
-                
-                 self.selectFirstPageItems(metadatasFromDB, observer: observer)
             })
         }
     }

+ 108 - 106
iOSClient/Main/CCMain.m

@@ -1133,23 +1133,20 @@
     });
     
     OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:self metadataNet:nil withUser:nil withUserID:nil withPassword:nil withUrl:nil];
-    [ocNetworking readFile:nil serverUrl:_serverUrl account:appDelegate.activeAccount success:^(NSString *account, tableMetadata *metadata) {
+    [ocNetworking readFileWithAccount:appDelegate.activeAccount serverUrl:_serverUrl fileName:nil completion:^(NSString *account, tableMetadata *metadata, NSString *message, NSInteger errorCode) {
+       
+        if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
         
-        if ([account isEqualToString:appDelegate.activeAccount]) {
-            
             tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", account, metadata.serverUrl]];
             
             // Change etag, read folder
             if ([metadata.etag isEqualToString:directory.etag] == NO) {
                 [self readFolder:metadata.serverUrl];
             }
-        }
-        
-    } failure:^(NSString *account, NSString *message, NSInteger errorCode) {
-        
-        // Unauthorized
-        if (errorCode == kOCErrorServerUnauthorized)
+            
+        } else if (errorCode == kOCErrorServerUnauthorized) {
             [appDelegate openLoginView:self loginType:k_login_Modify_Password selector:k_intro_login];
+        }
     }];
 }
 
@@ -1526,59 +1523,61 @@
         
         // Verify if exists the fileName TO
         OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:nil withUserID:nil withPassword:nil withUrl:nil];
-        [ocNetworking readFile:fileNameNew serverUrl:metadata.serverUrl account:appDelegate.activeAccount success:^(NSString *account, tableMetadata *metadata) {
+        [ocNetworking readFileWithAccount:appDelegate.activeAccount serverUrl:metadata.serverUrl fileName:fileNameNew completion:^(NSString *account, tableMetadata *metadata, NSString *message, NSInteger errorCode) {
             
-            UIAlertController * alert= [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
-            UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
-            }];
-            [alert addAction:ok];
-            [self presentViewController:alert animated:YES completion:nil];
-            
-        } failure:^(NSString *account, NSString *message, NSInteger errorCode) {
-            
-            NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", metadata.serverUrl, metadata.fileName];
-            NSString *fileNameToPath = [NSString stringWithFormat:@"%@/%@", metadata.serverUrl, fileNameNew];
-
-            [ocNetworking moveFileOrFolder:fileNamePath fileNameTo:fileNameToPath account:appDelegate.activeAccount success:^(NSString *account) {
+            if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
                 
-                // Rename metadata
-                (void) [[NCManageDatabase sharedInstance] renameMetadataWithFileNameTo:fileNameNew fileID:metadata.fileID];
+                UIAlertController * alert= [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
+                UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { }];
+                [alert addAction:ok];
+                [self presentViewController:alert animated:YES completion:nil];
                 
-                if (metadata.directory) {
+            } else if (errorCode != 0) {
+                
+                NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", metadata.serverUrl, metadata.fileName];
+                NSString *fileNameToPath = [NSString stringWithFormat:@"%@/%@", metadata.serverUrl, fileNameNew];
+                
+                [ocNetworking moveFileOrFolder:fileNamePath fileNameTo:fileNameToPath account:appDelegate.activeAccount success:^(NSString *account) {
                     
-                    NSString *serverUrl = [CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:metadata.fileName];
-                    NSString *serverUrlTo = [CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:fileNameNew];
+                    // Rename metadata
+                    (void) [[NCManageDatabase sharedInstance] renameMetadataWithFileNameTo:fileNameNew fileID:metadata.fileID];
                     
-                    tableDirectory *directoryTable = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", account, metadata.serverUrl]];
-                    if (directoryTable == nil) {
-                        [appDelegate messageNotification:@"_rename_" description:@"Internal error, ServerUrl not found" visible:true delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
-                        return;
+                    if (metadata.directory) {
+                        
+                        NSString *serverUrl = [CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:metadata.fileName];
+                        NSString *serverUrlTo = [CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:fileNameNew];
+                        
+                        tableDirectory *directoryTable = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", account, metadata.serverUrl]];
+                        if (directoryTable == nil) {
+                            [appDelegate messageNotification:@"_rename_" description:@"Internal error, ServerUrl not found" visible:true delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
+                            return;
+                        }
+                        
+                        [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:serverUrl serverUrlTo:serverUrlTo etag:nil fileID:nil encrypted:directoryTable.e2eEncrypted account:appDelegate.activeAccount];
+                        
+                    } else {
+                        
+                        [[NCManageDatabase sharedInstance] setLocalFileWithFileID:metadata.fileID date:nil exifDate:nil exifLatitude:nil exifLongitude:nil fileName:fileNameNew etag:nil];
+                        
+                        // Move file system
+                        
+                        NSString *atPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageFileID:metadata.fileID], metadata.fileName];
+                        NSString *toPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageFileID:metadata.fileID], fileNameNew];
+                        
+                        [[NSFileManager defaultManager] moveItemAtPath:atPath toPath:toPath error:nil];
+                        
+                        NSString *atPathIcon = [CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileName];
+                        NSString *toPathIcon = [CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:fileNameNew];
+                        
+                        [[NSFileManager defaultManager] moveItemAtPath:atPathIcon toPath:toPathIcon error:nil];
                     }
                     
-                    [[NCManageDatabase sharedInstance] setDirectoryWithServerUrl:serverUrl serverUrlTo:serverUrlTo etag:nil fileID:nil encrypted:directoryTable.e2eEncrypted account:appDelegate.activeAccount];
-                    
-                } else {
-                    
-                    [[NCManageDatabase sharedInstance] setLocalFileWithFileID:metadata.fileID date:nil exifDate:nil exifLatitude:nil exifLongitude:nil fileName:fileNameNew etag:nil];
-                    
-                    // Move file system
-                    
-                    NSString *atPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageFileID:metadata.fileID], metadata.fileName];
-                    NSString *toPath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageFileID:metadata.fileID], fileNameNew];
-                    
-                    [[NSFileManager defaultManager] moveItemAtPath:atPath toPath:toPath error:nil];
+                    [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadata.serverUrl fileID:metadata.fileID action:k_action_MOD];
                     
-                    NSString *atPathIcon = [CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileName];
-                    NSString *toPathIcon = [CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:fileNameNew];
-                    
-                    [[NSFileManager defaultManager] moveItemAtPath:atPathIcon toPath:toPathIcon error:nil];
-                }
-                
-                [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadata.serverUrl fileID:metadata.fileID action:k_action_MOD];
-
-            } failure:^(NSString *account, NSString *message, NSInteger errorCode) {
-                [appDelegate messageNotification:@"_rename_" description:message visible:true delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
-            }];
+                } failure:^(NSString *account, NSString *message, NSInteger errorCode) {
+                    [appDelegate messageNotification:@"_rename_" description:message visible:true delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
+                }];
+            }
         }];
     }
 }
@@ -1590,48 +1589,67 @@
 - (void)moveFileOrFolderMetadata:(tableMetadata *)metadata serverUrlTo:(NSString *)serverUrlTo numFile:(NSInteger)numFile ofFile:(NSInteger)ofFile
 {
     OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:nil withUserID:nil withPassword:nil withUrl:nil];
-    [ocNetworking readFile:metadata.fileName serverUrl:serverUrlTo account:appDelegate.activeAccount success:^(NSString *account, tableMetadata *metadata) {
-    
-        UIAlertController * alert= [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
-        UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
-        }];
-        [alert addAction:ok];
-        [self presentViewController:alert animated:YES completion:nil];
+    [ocNetworking readFileWithAccount:appDelegate.activeAccount serverUrl:serverUrlTo fileName:metadata.fileName completion:^(NSString *account, tableMetadata *metadata, NSString *message, NSInteger errorCode) {
         
-        // End Select Table View
-        [self tableViewSelect:NO];
-        
-        // reload Datasource
-        [self readFileReloadFolder];
-        
-    } failure:^(NSString *account, NSString *message, NSInteger errorCode) {
-    
-        NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", metadata.serverUrl, metadata.fileName];
-        NSString *fileNameToPath = [NSString stringWithFormat:@"%@/%@", serverUrlTo, metadata.fileName];
-        
-        [ocNetworking moveFileOrFolder:fileNamePath fileNameTo:fileNameToPath account:appDelegate.activeAccount success:^(NSString *account) {
+        if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
             
-            [_hud hideHud];
+            UIAlertController * alert= [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_file_already_exists_", nil) preferredStyle:UIAlertControllerStyleAlert];
+            UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
+            }];
+            [alert addAction:ok];
+            [self presentViewController:alert animated:YES completion:nil];
             
-            if (metadata.directory) {
-                [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:[CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:metadata.fileName] account:account];
-            }
+            // End Select Table View
+            [self tableViewSelect:NO];
             
-            [[NCManageDatabase sharedInstance] moveMetadataWithFileID:metadata.fileID serverUrlTo:serverUrlTo];
+            // reload Datasource
+            [self readFileReloadFolder];
             
-            [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:metadata.serverUrl account:account];
-            [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:serverUrlTo account:account];
+        } else if (errorCode != 0) {
             
-            // next
-            [_selectedFileIDsMetadatas removeObjectForKey:metadata.fileID];
+            NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", metadata.serverUrl, metadata.fileName];
+            NSString *fileNameToPath = [NSString stringWithFormat:@"%@/%@", serverUrlTo, metadata.fileName];
             
-            if ([_selectedFileIDsMetadatas count] > 0) {
+            [ocNetworking moveFileOrFolder:fileNamePath fileNameTo:fileNameToPath account:appDelegate.activeAccount success:^(NSString *account) {
                 
-                NSArray *metadatas = [_selectedFileIDsMetadatas allValues];
+                [_hud hideHud];
                 
-                [self moveFileOrFolderMetadata:[metadatas objectAtIndex:0] serverUrlTo:serverUrlTo numFile:[_selectedFileIDsMetadatas count] ofFile:_numSelectedFileIDsMetadatas];
+                if (metadata.directory) {
+                    [[NCManageDatabase sharedInstance] deleteDirectoryAndSubDirectoryWithServerUrl:[CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:metadata.fileName] account:account];
+                }
                 
-            } else {
+                [[NCManageDatabase sharedInstance] moveMetadataWithFileID:metadata.fileID serverUrlTo:serverUrlTo];
+                
+                [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:metadata.serverUrl account:account];
+                [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:serverUrlTo account:account];
+                
+                // next
+                [_selectedFileIDsMetadatas removeObjectForKey:metadata.fileID];
+                
+                if ([_selectedFileIDsMetadatas count] > 0) {
+                    
+                    NSArray *metadatas = [_selectedFileIDsMetadatas allValues];
+                    
+                    [self moveFileOrFolderMetadata:[metadatas objectAtIndex:0] serverUrlTo:serverUrlTo numFile:[_selectedFileIDsMetadatas count] ofFile:_numSelectedFileIDsMetadatas];
+                    
+                } else {
+                    
+                    // End Select Table View
+                    [self tableViewSelect:NO];
+                    
+                    // reload Datasource
+                    if (_isSearchMode)
+                        [self readFolder:metadata.serverUrl];
+                    else
+                        [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
+                }
+                
+            } failure:^(NSString *account, NSString *message, NSInteger errorCode) {
+                
+                [_hud hideHud];
+                
+                if (message && errorCode != kOCErrorServerUnauthorized)
+                    [appDelegate messageNotification:@"_move_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
                 
                 // End Select Table View
                 [self tableViewSelect:NO];
@@ -1640,27 +1658,11 @@
                 if (_isSearchMode)
                     [self readFolder:metadata.serverUrl];
                 else
-                    [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl fileID:nil action:k_action_NULL];
-            }
-            
-        } failure:^(NSString *account, NSString *message, NSInteger errorCode) {
-            
-            [_hud hideHud];
-            
-            if (message && errorCode != kOCErrorServerUnauthorized)
-                [appDelegate messageNotification:@"_move_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
-            
-            // End Select Table View
-            [self tableViewSelect:NO];
+                    [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadata.serverUrl fileID:nil action:k_action_NULL];
+            }];
             
-            // reload Datasource
-            if (_isSearchMode)
-                [self readFolder:metadata.serverUrl];
-            else
-                [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadata.serverUrl fileID:nil action:k_action_NULL];
-        }];
-        
-        [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_move_file_n_", nil), ofFile - numFile + 1, ofFile] mode:MBProgressHUDModeIndeterminate color:nil];
+            [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_move_file_n_", nil), ofFile - numFile + 1, ofFile] mode:MBProgressHUDModeIndeterminate color:nil];
+        }
     }];
 }
 

+ 33 - 33
iOSClient/Media/CCMedia.m

@@ -670,44 +670,44 @@
     NSString *startDirectory = [[NCManageDatabase sharedInstance] getAccountStartDirectoryMediaTabView:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl]];
     
     OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:self metadataNet:nil withUser:nil withUserID:nil withPassword:nil withUrl:nil];
-    [ocNetworking readFile:nil serverUrl:startDirectory account:appDelegate.activeAccount success:^(NSString *account, tableMetadata *metadata) {
-        
-        if (![metadata.etag isEqualToString:[saveEtagForStartDirectory objectForKey:startDirectory]] || sectionDataSource.allRecordsDataSource.count == 0) {
-            
-            isSearchMode = YES;
-            [self editingModeNO];
-            
-            [ocNetworking searchWithAccount:appDelegate.activeAccount fileName:@"" serverUrl:startDirectory contentType:@[@"image/%", @"video/%"] date:[NSDate distantPast] depth:@"infinity" completion:^(NSString *account, NSArray *metadatas, NSString *message, NSInteger errorCode) {
-               
-                if (errorCode == 0 && [appDelegate.activeAccount isEqualToString:account]) {
+    [ocNetworking readFileWithAccount:appDelegate.activeAccount serverUrl:startDirectory fileName:nil completion:^(NSString *account, tableMetadata *metadata, NSString *message, NSInteger errorCode) {
+
+        if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
+            if (![metadata.etag isEqualToString:[saveEtagForStartDirectory objectForKey:startDirectory]] || sectionDataSource.allRecordsDataSource.count == 0) {
+                
+                isSearchMode = YES;
+                [self editingModeNO];
+                
+                [ocNetworking searchWithAccount:appDelegate.activeAccount fileName:@"" serverUrl:startDirectory contentType:@[@"image/%", @"video/%"] date:[NSDate distantPast] depth:@"infinity" completion:^(NSString *account, NSArray *metadatas, NSString *message, NSInteger errorCode) {
                     
-                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
-                        
-                        // Clear all Hardcoded new foto/video from CCNetworking
-                        [self.addMetadatasFromUpload removeAllObjects];
-                        
-                        [[NCManageDatabase sharedInstance] createTablePhotos:metadatas account:account];
+                    if (errorCode == 0 && [appDelegate.activeAccount isEqualToString:account]) {
                         
-                        dispatch_async(dispatch_get_main_queue(), ^{
-                            [self reloadDatasource:nil action:k_action_NULL];
+                        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
+                            
+                            // Clear all Hardcoded new foto/video from CCNetworking
+                            [self.addMetadatasFromUpload removeAllObjects];
+                            
+                            [[NCManageDatabase sharedInstance] createTablePhotos:metadatas account:account];
+                            
+                            dispatch_async(dispatch_get_main_queue(), ^{
+                                [self reloadDatasource:nil action:k_action_NULL];
+                            });
+                            
+                            // Update date
+                            [[NCManageDatabase sharedInstance] setAccountDateSearchContentTypeImageVideo:[NSDate date]];
+                            // Save etag
+                            [saveEtagForStartDirectory setObject:metadata.etag forKey:metadata.serverUrl];
                         });
                         
-                        // Update date
-                        [[NCManageDatabase sharedInstance] setAccountDateSearchContentTypeImageVideo:[NSDate date]];
-                        // Save etag
-                        [saveEtagForStartDirectory setObject:metadata.etag forKey:metadata.serverUrl];
-                    });
-                    
-                } else {
-                    [self reloadDatasource:nil action:k_action_NULL];
-                }
-            }];
-            
-        } else {
-            [self reloadDatasource:nil action:k_action_NULL];
+                    } else {
+                        [self reloadDatasource:nil action:k_action_NULL];
+                    }
+                }];
+                
+            } else {
+                [self reloadDatasource:nil action:k_action_NULL];
+            }
         }
-        
-    } failure:^(NSString *account, NSString *message, NSInteger errorCode) {
     }];
 }
 

+ 8 - 8
iOSClient/Move/CCMove.m

@@ -280,16 +280,16 @@
 - (void)readFile
 {
     OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:nil withUserID:nil withPassword:nil withUrl:nil];
-    [ocNetworking readFile:nil serverUrl:_serverUrl account:activeAccount success:^(NSString *account, tableMetadata *metadata) {
-        
-        tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", account, _serverUrl]];
-            
-        if ([metadata.etag isEqualToString:directory.etag] == NO) {
+    [ocNetworking readFileWithAccount:activeAccount serverUrl:_serverUrl fileName:nil completion:^(NSString *account, tableMetadata *metadata, NSString *message, NSInteger errorCode) {
+        if (errorCode == 0) {
+            tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", account, _serverUrl]];
+            if ([metadata.etag isEqualToString:directory.etag] == NO) {
+                [self readFolder];
+            }
+        } else {
             [self readFolder];
+
         }
-        
-    } failure:^(NSString *account, NSString *message, NSInteger errorCode) {
-        [self readFolder];
     }];
 }
 

+ 1 - 1
iOSClient/Networking/OCNetworking.h

@@ -57,7 +57,7 @@
 
 - (void)readFolderWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl depth:(NSString *)depth completion:(void(^)(NSString *account, NSArray *metadatas, tableMetadata *metadataFolder, NSString *message, NSInteger errorCode))completion;
 
-- (void)readFile:(NSString *)fileName serverUrl:(NSString *)serverUrl account:(NSString *)account success:(void(^)(NSString *account, tableMetadata *metadata))success failure:(void (^)(NSString *account, NSString *message, NSInteger errorCode))failure;
+- (void)readFileWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl fileName:(NSString *)fileName completion:(void(^)(NSString *account, tableMetadata *metadata, NSString *message, NSInteger errorCode))completion;
 
 - (void)searchWithAccount:(NSString *)account fileName:(NSString *)fileName serverUrl:(NSString *)serverUrl contentType:(NSArray *)contentType date:(NSDate *)date depth:(NSString *)depth completion:(void(^)(NSString *account, NSArray *metadatas, NSString *message, NSInteger errorCode))completion;
 

+ 5 - 5
iOSClient/Networking/OCNetworking.m

@@ -649,11 +649,11 @@
 #pragma mark ===== ReadFile =====
 #pragma --------------------------------------------------------------------------------------------
 
-- (void)readFile:(NSString *)fileName serverUrl:(NSString *)serverUrl account:(NSString *)account success:(void(^)(NSString *account, tableMetadata *metadata))success failure:(void (^)(NSString *account, NSString *message, NSInteger errorCode))failure
+- (void)readFileWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl fileName:(NSString *)fileName completion:(void(^)(NSString *account, tableMetadata *metadata, NSString *message, NSInteger errorCode))completion
 {
     tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
     if (tableAccount == nil) {
-        failure(account, NSLocalizedString(@"_error_user_not_available_", nil), k_CCErrorUserNotAvailble);
+        completion(account, nil, NSLocalizedString(@"_error_user_not_available_", nil), k_CCErrorUserNotAvailble);
     }
     
     OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
@@ -685,7 +685,7 @@
                     
             metadata = [CCUtility trasformedOCFileToCCMetadata:itemDto fileName:fileName serverUrl:serverUrl autoUploadFileName:autoUploadFileName autoUploadDirectory:autoUploadDirectory activeAccount:account isFolderEncrypted:isFolderEncrypted];
                     
-            success(account, metadata);
+            completion(account, metadata, nil, 0);
             
         // BUG 1038 item == 0
         } else {
@@ -695,7 +695,7 @@
                 
             [appDelegate messageNotification:@"Server error" description:@"Read File WebDAV : [items NULL] please fix" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
 #endif
-            failure(account, NSLocalizedString(@"Read File WebDAV : [items NULL] please fix", nil), k_CCErrorInternalError);
+            completion(account, nil, NSLocalizedString(@"Read File WebDAV : [items NULL] please fix", nil), k_CCErrorInternalError);
         }
         
     } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
@@ -719,7 +719,7 @@
         // Activity
         [[NCManageDatabase sharedInstance] addActivityClient:serverUrl fileID:@"" action:k_activityDebugActionReadFolder selector:@"" note:[error.userInfo valueForKey:@"NSLocalizedDescription"] type:k_activityTypeFailure verbose:k_activityVerboseHigh activeUrl:tableAccount.url];
         
-        failure(account, message, errorCode);
+        completion(account, nil, message, errorCode);
     }];
 }
 

+ 3 - 5
iOSClient/Select/NCSelect.swift

@@ -496,12 +496,10 @@ class NCSelect: UIViewController ,UICollectionViewDataSource, UICollectionViewDe
             } else if errorCode != 0 {
                 
                 self.appDelegate.messageNotification("_error_", description: message, visible: true, delay: TimeInterval(k_dismissAfterSecond), type: TWMessageBarMessageType.error, errorCode: errorCode)
-                
-                DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
-                    self.networkInProgress = false
-                    self.loadDatasource(withLoadFolder: false)
-                }
             }
+            
+            self.networkInProgress = false
+            self.loadDatasource(withLoadFolder: false)
         })
     }
     

+ 9 - 6
iOSClient/Shares/NCShares.m

@@ -294,13 +294,16 @@
         cell.fileImageView.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"file"] multiplier:2 color:[NCBrandColor sharedInstance].brandElement];
         
         OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:nil withUserID:nil withPassword:nil withUrl:nil];
-        [ocNetworking readFile:table.fileName serverUrl:table.serverUrl account:appDelegate.activeAccount success:^(NSString *account, tableMetadata *metadata) {
-        
-            (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
-            [self reloadDatasource];
+        [ocNetworking readFileWithAccount:appDelegate.activeAccount serverUrl:table.serverUrl fileName:table.fileName completion:^(NSString *account, tableMetadata *metadata, NSString *message, NSInteger errorCode) {
             
-        } failure:^(NSString *account, NSString *message, NSInteger errorCode) {
-            NSLog(@"[LOG] Read file failure error %d, %@", (int)errorCode, message);
+            if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
+                
+                (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
+                [self reloadDatasource];
+                
+            } else {
+                
+            }
         }];
     }
     

+ 17 - 18
iOSClient/Synchronize/CCSynchronize.m

@@ -207,26 +207,25 @@
 - (void)readFile:(NSString *)fileID fileName:(NSString *)fileName serverUrl:(NSString *)serverUrl selector:(NSString *)selector
 {
     OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:nil withUserID:nil withPassword:nil withUrl:nil];
-    [ocNetworking readFile:fileName serverUrl:serverUrl account:appDelegate.activeAccount success:^(NSString *account, tableMetadata *metadata) {
-
-        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
-            
-            BOOL withDownload = NO;
-            
-            if ([selector isEqualToString:selectorReadFileWithDownload])
-                withDownload = YES;
+    [ocNetworking readFileWithAccount:appDelegate.activeAccount serverUrl:serverUrl fileName:fileName completion:^(NSString *account, tableMetadata *metadata, NSString *message, NSInteger errorCode) {
+        
+        if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
             
-            //Add/Update Metadata
-            tableMetadata *addMetadata = [[NCManageDatabase sharedInstance] addMetadata:metadata];
+            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
+                
+                BOOL withDownload = NO;
+                
+                if ([selector isEqualToString:selectorReadFileWithDownload])
+                    withDownload = YES;
+                
+                //Add/Update Metadata
+                tableMetadata *addMetadata = [[NCManageDatabase sharedInstance] addMetadata:metadata];
+                
+                if (addMetadata)
+                    [self verifyChangeMedatas:[[NSArray alloc] initWithObjects:addMetadata, nil] serverUrl:serverUrl account:appDelegate.activeAccount withDownload:withDownload];
+            });
             
-            if (addMetadata)
-                [self verifyChangeMedatas:[[NSArray alloc] initWithObjects:addMetadata, nil] serverUrl:serverUrl account:appDelegate.activeAccount withDownload:withDownload];
-        });
-
-    } failure:^(NSString *account, NSString *message, NSInteger errorCode) {
-
-        // File not present, remove it
-        if (errorCode == 404) {
+        } else if (errorCode == 404) {
             
             [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
             [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];