浏览代码

fix listing

Marino Faggiana 7 年之前
父节点
当前提交
bb62e6577f
共有 1 个文件被更改,包括 36 次插入17 次删除
  1. 36 17
      iOSClient/Networking/OCNetworking.m

+ 36 - 17
iOSClient/Networking/OCNetworking.m

@@ -289,7 +289,7 @@
                 
                 OCFileDto *itemDto = [itemsSortedArray objectAtIndex:i];
                 
-                NSString *fileName = [itemDto.fileName  stringByReplacingOccurrencesOfString:@"/" withString:@""];
+                NSString *fileName = [itemDto.fileName stringByReplacingOccurrencesOfString:@"/" withString:@""];
                 
                 // Skip hidden files
                 if (fileName.length > 0) {
@@ -302,7 +302,7 @@
                         
                     serverUrl = [CCUtility stringAppendServerUrl:_metadataNet.serverUrl addFileName:fileName];
                         
-                    (void)[[NCManageDatabase sharedInstance] addDirectoryWithServerUrl:serverUrl fileID:itemDtoFolder.ocId permissions:itemDtoFolder.permissions encrypted:itemDto.isEncrypted];
+                    (void)[[NCManageDatabase sharedInstance] addDirectoryWithServerUrl:serverUrl fileID:itemDto.ocId permissions:itemDto.permissions encrypted:itemDto.isEncrypted];
                 }
                 
                 // ----- BUG #942 ---------
@@ -550,9 +550,10 @@
         
         for(OCFileDto *itemDto in items) {
             
-            NSString *serverUrl, *fileName;
+            NSString *serverUrl, *fileName, *directoryID;
+            BOOL isFolderEncrypted;
             
-            fileName = [itemDto.fileName  stringByReplacingOccurrencesOfString:@"/" withString:@""];
+            fileName = [itemDto.fileName stringByReplacingOccurrencesOfString:@"/" withString:@""];
             
             // Skip hidden files
             if (fileName.length > 0) {
@@ -572,27 +573,45 @@
             }
             // ------------------------
             
-            NSRange firstInstance = [itemDto.filePath rangeOfString:[NSString stringWithFormat:@"%@/files/%@", dav, _activeUserID]];
-            NSRange finalRange = NSMakeRange(firstInstance.location + firstInstance.length, itemDto.filePath.length-(firstInstance.location + firstInstance.length));
-            
-            if (finalRange.location != NSNotFound && finalRange.location + finalRange.length <= itemDto.filePath.length) {
-                // It's safe to use range on str
-                serverUrl = [itemDto.filePath substringWithRange:finalRange];
-            } else {
-                continue;
-            }
-
-            /* TRIM */
+            /*
+             NSRange firstInstance = [itemDto.filePath rangeOfString:[NSString stringWithFormat:@"%@/files/%@", dav, _activeUserID]];
+             NSRange finalRange = NSMakeRange(firstInstance.location + firstInstance.length, itemDto.filePath.length-(firstInstance.location + firstInstance.length));
+             
+             if (finalRange.location != NSNotFound && finalRange.location + finalRange.length <= itemDto.filePath.length) {
+             // It's safe to use range on str
+             serverUrl = [itemDto.filePath substringWithRange:finalRange];
+             } else {
+             continue;
+             }
+             
             if ([serverUrl hasPrefix:@"/"])
                 serverUrl = [serverUrl substringFromIndex:1];
             if ([serverUrl hasSuffix:@"/"])
                 serverUrl = [serverUrl substringToIndex:[serverUrl length] - 1];
-            /*      */
             
             serverUrl = [CCUtility stringAppendServerUrl:[_activeUrl stringByAppendingString:webDAV] addFileName:serverUrl];
-
+            
             NSString *directoryID = [[NCManageDatabase sharedInstance] addDirectoryWithServerUrl:serverUrl fileID:itemDto.ocId permissions:itemDto.permissions encrypted:itemDto.isEncrypted];
             BOOL isFolderEncrypted = [CCUtility isFolderEncrypted:serverUrl account:_metadataNet.account];
+            
+            [metadatas addObject:[CCUtility trasformedOCFileToCCMetadata:itemDto fileName:itemDto.fileName serverUrl:serverUrl directoryID:directoryID autoUploadFileName:autoUploadFileName autoUploadDirectory:autoUploadDirectory activeAccount:_metadataNet.account directoryUser:directoryUser isFolderEncrypted:isFolderEncrypted]];
+            */
+            
+            serverUrl = [itemDto.filePath stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@/files/%@", dav, _activeUserID] withString:@""];
+            if ([serverUrl hasPrefix:@"/"])
+                serverUrl = [serverUrl substringFromIndex:1];
+            if ([serverUrl hasSuffix:@"/"])
+                serverUrl = [serverUrl substringToIndex:[serverUrl length] - 1];
+            serverUrl = [CCUtility stringAppendServerUrl:[_activeUrl stringByAppendingString:webDAV] addFileName:serverUrl];
+            
+            if (itemDto.isDirectory) {
+                serverUrl = [NSString stringWithFormat:@"%@/%@", serverUrl, fileName];
+                directoryID = [[NCManageDatabase sharedInstance] addDirectoryWithServerUrl:serverUrl fileID:itemDto.ocId permissions:itemDto.permissions encrypted:itemDto.isEncrypted];
+                isFolderEncrypted = itemDto.isEncrypted;
+            } else {
+                directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrl];
+                isFolderEncrypted = [CCUtility isFolderEncrypted:serverUrl account:_metadataNet.account];
+            }
 
             [metadatas addObject:[CCUtility trasformedOCFileToCCMetadata:itemDto fileName:itemDto.fileName serverUrl:serverUrl directoryID:directoryID autoUploadFileName:autoUploadFileName autoUploadDirectory:autoUploadDirectory activeAccount:_metadataNet.account directoryUser:directoryUser isFolderEncrypted:isFolderEncrypted]];
         }