Marino Faggiana 7 years ago
parent
commit
1655523e59
2 changed files with 16 additions and 14 deletions
  1. 8 7
      iOSClient/Database/NCManageDatabase.swift
  2. 8 7
      iOSClient/Settings/CCAdvanced.m

+ 8 - 7
iOSClient/Database/NCManageDatabase.swift

@@ -752,13 +752,7 @@ class NCManageDatabase: NSObject {
         
         try! realm.write {
             
-            if result != nil {
-                
-                result?.permissions = permissions
-                directoryID = result!.directoryID
-                realm.add(result!, update: true)
-                
-            } else {
+            if result == nil || (result?.isInvalidated)! {
                 
                 let addDirectory = tableDirectory()
                 addDirectory.account = tableAccount!.account
@@ -769,6 +763,13 @@ class NCManageDatabase: NSObject {
                 addDirectory.permissions = permissions
                 addDirectory.serverUrl = serverUrl
                 realm.add(addDirectory, update: true)
+                
+            } else {
+                
+                result?.permissions = permissions
+                directoryID = result!.directoryID
+                realm.add(result!, update: true)
+
             }
         }
         

+ 8 - 7
iOSClient/Settings/CCAdvanced.m

@@ -304,14 +304,15 @@
         
         [self.hud visibleHudTitle:NSLocalizedString(@"_remove_cache_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
         
-        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
+        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC),dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
             
             [app cancelAllOperations];
+            
             [[CCNetworking sharedNetworking] settingSessionsDownload:YES upload:YES taskStatus:k_taskStatusCancel activeAccount:app.activeAccount activeUser:app.activeUser activeUrl:app.activeUrl];
             
             [[NSURLCache sharedURLCache] setMemoryCapacity:0];
             [[NSURLCache sharedURLCache] setDiskCapacity:0];
-            
+
             [[NCManageDatabase sharedInstance] clearTable:[tableActivity class] account:app.activeAccount];
             [[NCManageDatabase sharedInstance] clearTable:[tableAutomaticUpload class] account:app.activeAccount];
             [[NCManageDatabase sharedInstance] clearTable:[tableCapabilities class] account:app.activeAccount];
@@ -332,12 +333,12 @@
             
             [self recalculateSize];
             
-            // Inizialized home
-            [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil];
-            
-            [self.hud hideHud];
+            dispatch_async(dispatch_get_main_queue(), ^{
+                // Inizialized home
+                [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"initializeMain" object:nil];
+                [self.hud hideHud];
+            });
         });
-        
     }]];
 
     [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {