Marino Faggiana 8 years ago
parent
commit
ebf3607670
2 changed files with 31 additions and 9 deletions
  1. 12 0
      iOSClient/Networking/OCNetworking.m
  2. 19 9
      iOSClient/Offline/CCSynchronize.m

+ 12 - 0
iOSClient/Networking/OCNetworking.m

@@ -556,6 +556,18 @@
         NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:_metadataNet.account activeUrl:_activeUrl];
         NSString *directoryUser = [CCUtility getDirectoryActiveUser:_activeUser activeUrl:_activeUrl];
         
+        // Order by fileNamePath
+        items = [items sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
+            
+            OCFileDto *record1 = obj1, *record2 = obj2;
+            
+            NSString *path1 = [[record1.filePath stringByAppendingString:record1.fileName] lowercaseString];
+            NSString *path2 = [[record2.filePath stringByAppendingString:record2.fileName] lowercaseString];
+            
+            return [path1 compare:path2];
+            
+        }];
+        
         for(OCFileDto *itemDto in items) {
             
             itemDto.fileName = [itemDto.fileName stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

+ 19 - 9
iOSClient/Offline/CCSynchronize.m

@@ -90,6 +90,8 @@
     if (![record.account isEqualToString:metadataNet.account])
         return;
     
+    NSString *father = @"";
+    
     for (CCMetadata *metadata in metadatas) {
         
         // Delete Record NOT in session
@@ -121,17 +123,25 @@
         // end test, insert in CoreData
         [CCCoreData addMetadata:metadata activeAccount:app.activeAccount activeUrl:app.activeUrl context:nil];
         
-        if (metadata.directory) {
-            
-            NSString* serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:app.activeAccount];
-            serverUrl = [CCUtility stringAppendServerUrl:serverUrl addServerUrl:metadata.fileNameData];
-            NSString *directoryID = [CCCoreData getDirectoryIDFromServerUrl:serverUrl activeAccount:app.activeAccount];
-            
-            [self readFolderServerUrl:serverUrl directoryID:directoryID];
+        // ---- Synchronized ----
+        
+        // Get ServerUrl
+        NSString* serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:app.activeAccount];
+        serverUrl = [CCUtility stringAppendServerUrl:serverUrl addServerUrl:metadata.fileNameData];
+        
+        if (![serverUrl containsString:father]) {
             
-        } else {
+            if (metadata.directory) {
+                
+                NSString *directoryID = [CCCoreData getDirectoryIDFromServerUrl:serverUrl activeAccount:app.activeAccount];
+                [self readFolderServerUrl:serverUrl directoryID:directoryID];
+                
+            } else {
+                
+                [self readFile:metadata];
+            }
             
-            [self readFile:metadata];
+            father = serverUrl;
         }
     }
 }