Marino Faggiana 6 years ago
parent
commit
ee458b1f36

+ 3 - 5
iOSClient/Actions/CCActions.swift

@@ -408,16 +408,14 @@ class CCActions: NSObject {
     // --------------------------------------------------------------------------------------------
     
     @objc func deleteFile(metadata: tableMetadata, serverUrl: String) {
-        
-        let fileNamePath = appDelegate.directoryUser + "/" + metadata.fileID
-        
+                
         do {
-            try FileManager.default.removeItem(atPath: fileNamePath)
+            try FileManager.default.removeItem(atPath: CCUtility.getDirectoryProviderStorageFileID(metadata.fileID))
         } catch {
             // handle error
         }
         do {
-            try FileManager.default.removeItem(atPath: fileNamePath + ".ico")
+            try FileManager.default.removeItem(atPath: appDelegate.directoryUser + "/" + metadata.fileID + ".ico")
         } catch {
             // handle error
         }

+ 1 - 1
iOSClient/Activity/CCActivity.m

@@ -351,7 +351,7 @@
     tableActivity *activity = [_sectionDataSource objectAtIndex:indexPath.section];
     tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", activity.fileID]];
     
-    BOOL existsFile = [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, activity.fileID]];
+    BOOL existsFile = [[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]];
     
     if (metadata && existsFile) {
         

+ 2 - 7
iOSClient/AppDelegate.m

@@ -1339,11 +1339,11 @@
         
         [[NCManageDatabase sharedInstance] setMetadataSession:nil sessionError:@"" sessionSelector:nil sessionSelectorPost:nil sessionTaskIdentifier:k_taskIdentifierDone status:k_metadataStatusWaitDownload predicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
     }
-    else if ([[_listChangeTask objectForKey:metadata.fileID] isEqualToString:@"cancelUpload"]) {
+    else if ([[_listChangeTask objectForKey:fileID] isEqualToString:@"cancelUpload"]) {
         
         // remove the file
         
-        [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", self.directoryUser, fileID] error:nil];
+        [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorage], fileID] error:nil];
         [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.ico", self.directoryUser, fileID] error:nil];
         
         [[NCManageDatabase sharedInstance] deleteMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID] clearDateReadDirectoryID:nil];
@@ -1483,11 +1483,6 @@
         if (metadataForUpload) {
             
             if ([metadataForUpload.session isEqualToString:k_upload_session_extension]) {
-                
-                NSString *atPath = [NSString stringWithFormat:@"%@/%@", metadataForUpload.path, metadataForUpload.fileName];
-                NSString *toPath = [NSString stringWithFormat:@"%@/%@", self.directoryUser, metadataForUpload.fileName];
-                [CCUtility copyFileAtPath:atPath toPath:toPath];
-                
                 metadataForUpload.session = k_upload_session;
             }
             

+ 0 - 1
iOSClient/AutoUpload/NCAutoUpload.m

@@ -426,7 +426,6 @@
         metadataForUpload.fileID = [directoryID stringByAppendingString:fileName];
         metadataForUpload.fileName = fileName;
         metadataForUpload.fileNameView = fileName;
-        metadataForUpload.path = appDelegate.directoryUser;
         metadataForUpload.session = session;
         metadataForUpload.sessionSelector = selector;
         metadataForUpload.status = k_metadataStatusWaitUpload;

+ 5 - 4
iOSClient/Create/CCCreateCloud.swift

@@ -631,7 +631,9 @@ class CreateFormUploadFile: XLFormViewController, CCMoveDelegate {
         self.dismiss(animated: true, completion: {
             
             let data = self.text.data(using: .utf8)
-            let success = FileManager.default.createFile(atPath: "\(self.appDelegate.directoryUser!)/\(fileNameSave)", contents: data, attributes: nil)
+            let directoryID = NCManageDatabase.sharedInstance.getDirectoryID(self.serverUrl)!
+            let fileID = directoryID + fileNameSave
+            let success = FileManager.default.createFile(atPath: CCUtility.getDirectoryProviderStorageFileID(fileID, fileNameView: fileNameSave), contents: data, attributes: nil)
             
             if success {
                 
@@ -639,11 +641,10 @@ class CreateFormUploadFile: XLFormViewController, CCMoveDelegate {
                 
                 metadataForUpload.account = self.appDelegate.activeAccount
                 metadataForUpload.date = NSDate()
-                metadataForUpload.directoryID = NCManageDatabase.sharedInstance.getDirectoryID(self.serverUrl)!
-                metadataForUpload.fileID = metadataForUpload.directoryID + fileNameSave
+                metadataForUpload.directoryID = directoryID
+                metadataForUpload.fileID = fileID
                 metadataForUpload.fileName = fileNameSave
                 metadataForUpload.fileNameView = fileNameSave
-                metadataForUpload.path = self.appDelegate.directoryUser!
                 metadataForUpload.session = k_upload_session
                 metadataForUpload.sessionSelector = selectorUploadFile
                 metadataForUpload.status = Int(k_metadataStatusWaitUpload)

+ 4 - 7
iOSClient/Favorites/CCFavorites.m

@@ -333,14 +333,11 @@
 
 - (void)openWith:(tableMetadata *)metadata
 {
-    NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID];
+    NSString *fileNamePath = [CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView];
     
     if ([[NSFileManager defaultManager] fileExistsAtPath:fileNamePath]) {
         
-        [[NSFileManager defaultManager] removeItemAtPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNameView] error:nil];
-        [[NSFileManager defaultManager] linkItemAtPath:fileNamePath toPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNameView] error:nil];
-        
-        NSURL *url = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNameView]];
+        NSURL *url = [NSURL fileURLWithPath:fileNamePath];
         
         _docController = [UIDocumentInteractionController interactionControllerWithURL:url];
         _docController.delegate = self;
@@ -650,7 +647,7 @@
         
         NSString *date = [CCUtility dateDiff:metadata.date];
         NSString *length = [CCUtility transformedSize:metadata.size];
-        BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID]];
+        BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]];
             
         if (fileExists)
             cell.local.image = [UIImage imageNamed:@"local"];
@@ -724,7 +721,7 @@
         NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
 
         if (serverUrl) {
-            if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, _metadata.fileID]]) {
+            if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageFileID:_metadata.fileID fileNameView:_metadata.fileNameView]]) {
             
                 [self downloadFileSuccessFailure:_metadata.fileName fileID:_metadata.fileID serverUrl:serverUrl selector:selectorLoadFileView selectorPost:@"" errorMessage:@"" errorCode:0];
                             

+ 18 - 40
iOSClient/Main/CCDetail.m

@@ -276,25 +276,21 @@
 
 - (void)viewDocument
 {
-    NSString *fileName;
     CGFloat safeAreaBottom = 0;
     
     if (@available(iOS 11, *)) {
         safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
     }
     
-    fileName = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileNameView];
-        
-    [[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];
-    [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
+    NSString *fileNamePath = [CCUtility getDirectoryProviderStorageFileID:self.metadataDetail.fileID fileNameView:self.metadataDetail.fileNameView];
     
-    if ([[NSFileManager defaultManager] fileExistsAtPath:fileName] == NO) {
+    if ([[NSFileManager defaultManager] fileExistsAtPath:fileNamePath] == NO) {
         
         [self backNavigationController];
         return;
     }
     
-    NSURL *url = [NSURL fileURLWithPath:fileName];
+    NSURL *url = [NSURL fileURLWithPath:fileNamePath];
 
     WKPreferences *wkPreferences = [[WKPreferences alloc] init];
     wkPreferences.javaScriptEnabled = true;
@@ -430,7 +426,7 @@
         
         tableMetadata *metadataDB = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
 
-        if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID]] == NO && [metadataDB.session length] == 0)
+        if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]] == NO && [metadataDB.session length] == 0)
             [self downloadPhotoBrowser:metadata];
     }
     
@@ -451,7 +447,7 @@
             
             if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {
                 
-                NSString *fileImage = [NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID];
+                NSString *fileImage = [CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView];
                 NSString *ext = [CCUtility getExtension:metadata.fileNameView];
                 
                 if ([ext isEqualToString:@"GIF"]) image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
@@ -477,14 +473,9 @@
             
             if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) {
                 
-                if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID]]) {
-                    
-                    // remove and make the simbolic link in temp
-                    NSString *toPath = [NSTemporaryDirectory() stringByAppendingString:metadata.fileNameView];
+                if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]]) {
                     
-                    [[NSFileManager defaultManager] removeItemAtPath:toPath error:nil];
-                    [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID] toPath:toPath error:nil];
-                    NSURL *url = [NSURL fileURLWithPath:toPath];
+                    NSURL *url = [NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]];
                     
                     MWPhoto *video = [MWPhoto photoWithImage:[CCGraphics thumbnailImageForVideo:url atTime:1.0]];
                     video.videoURL = url;
@@ -502,17 +493,12 @@
             
             if ([metadata.typeFile isEqualToString: k_metadataTypeFile_audio]) {
                 
-                if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID]]) {
+                if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]]) {
                     
                     MWPhoto *audio;
                     UIImage *audioImage;
                     
-                    // remove and make the simbolic link in temp
-                    NSString *toPath = [NSTemporaryDirectory() stringByAppendingString:metadata.fileNameView];
-                    
-                    [[NSFileManager defaultManager] removeItemAtPath:toPath error:nil];
-                    [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID] toPath:toPath error:nil];
-                    NSURL *url = [NSURL fileURLWithPath:toPath];
+                    NSURL *url = [NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]];
                     
                     if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, metadata.fileID]]) {
                         audioImage = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, metadata.fileID]];
@@ -560,13 +546,8 @@
 {
     tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
     if (metadata == nil) return;
-    
-    NSString *filePath = [NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileNameView];
-        
-    [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
-    [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID] toPath:filePath error:nil];
-    
-    self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
+
+    self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]]];
     
     self.docController.delegate = self;
     
@@ -586,7 +567,7 @@
 - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser deleteButtonPressedForPhotoAtIndex:(NSUInteger)index deleteButton:(UIBarButtonItem *)deleteButton
 {
     tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
-    if (metadata == nil || [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID]] == NO) {
+    if (metadata == nil || [[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]] == NO) {
         
         [appDelegate messageNotification:@"_info_" description:@"_file_not_found_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
         
@@ -745,12 +726,9 @@
 
 - (void)viewPDF:(NSString *)password
 {
-    NSString *fileName = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileNameView];
-        
-    [[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];
-    [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
+    NSString *fileNamePath = [CCUtility getDirectoryProviderStorageFileID:self.metadataDetail.fileID fileNameView:self.metadataDetail.fileNameView];
     
-    if ([[NSFileManager defaultManager] fileExistsAtPath:fileName isDirectory:nil] == NO) {
+    if ([[NSFileManager defaultManager] fileExistsAtPath:fileNamePath isDirectory:nil] == NO) {
         
         // read file error
         UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
@@ -760,7 +738,7 @@
         [self presentViewController:alertController animated:YES completion:nil];
     }
     
-    CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL fileURLWithPath:fileName]);
+    CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL fileURLWithPath:fileNamePath]);
     
     if (pdf) {
         
@@ -771,7 +749,7 @@
             if (CGPDFDocumentUnlockWithPassword(pdf, "") == YES) {
                 
                 // blank password
-                [self readerPDF:fileName password:@""];
+                [self readerPDF:fileNamePath password:@""];
                 
             } else {
                 
@@ -799,7 +777,7 @@
                     } else {
                         
                         // pdf with password
-                        [self readerPDF:fileName password:password];
+                        [self readerPDF:fileNamePath password:password];
                     }
                 }
             }
@@ -807,7 +785,7 @@
         } else{
             
             // No password
-            [self readerPDF:fileName password:@""];
+            [self readerPDF:fileNamePath password:@""];
         }
         
     } else {

+ 42 - 92
iOSClient/Main/CCMain.m

@@ -705,30 +705,29 @@
 {
     if (controller.documentPickerMode == UIDocumentPickerModeImport) {
         
-        NSString *serverUrl = [appDelegate getTabBarControllerActiveServerUrl];
-        
         NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
         __block NSError *error;
         
         [coordinator coordinateReadingItemAtURL:url options:NSFileCoordinatorReadingForUploading error:&error byAccessor:^(NSURL *newURL) {
             
             NSString *fileName = [url lastPathComponent];
-            NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, fileName];
+            NSString *serverUrl = [appDelegate getTabBarControllerActiveServerUrl];
+            NSString *directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrl];
+            NSString *fileID = [directoryID stringByAppendingString:fileName];
             NSData *data = [NSData dataWithContentsOfURL:newURL];
             
             if (data && error == nil) {
                 
-                if ([data writeToFile:fileNamePath options:NSDataWritingAtomic error:&error]) {
+                if ([data writeToFile:[CCUtility getDirectoryProviderStorageFileID:fileID fileNameView:fileName] options:NSDataWritingAtomic error:&error]) {
                     
                     tableMetadata *metadataForUpload = [tableMetadata new];
                     
                     metadataForUpload.account = appDelegate.activeAccount;
                     metadataForUpload.date = [NSDate new];
-                    metadataForUpload.directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:serverUrl];
-                    metadataForUpload.fileID = [metadataForUpload.directoryID stringByAppendingString:fileName];
+                    metadataForUpload.directoryID = directoryID;
+                    metadataForUpload.fileID = fileID;
                     metadataForUpload.fileName = fileName;
                     metadataForUpload.fileNameView = fileName;
-                    metadataForUpload.path = appDelegate.directoryUser;
                     metadataForUpload.session = k_upload_session;
                     metadataForUpload.sessionSelector = selectorUploadFile;
                     metadataForUpload.status = k_metadataStatusWaitUpload;
@@ -1131,9 +1130,13 @@
             
             [self reloadDatasource:serverUrl];
             
+            /*
             [[NSFileManager defaultManager] removeItemAtPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNameView] error:nil];
             [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID] toPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNameView] error:nil];
             NSURL *url = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNameView]];
+            */
+            
+            NSURL *url = [NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]];
             
             _docController = [UIDocumentInteractionController interactionControllerWithURL:url];
             _docController.delegate = self;
@@ -1144,12 +1147,13 @@
         // Save to Photo Album
         if ([selector isEqualToString:selectorSave] && [[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
             
-            NSString *file = [NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID];
+//            NSString *file = [NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID];
+            NSString *fileNamePath = [CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView];
             PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
             
             if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] && status == PHAuthorizationStatusAuthorized) {
                 
-                UIImage *image = [UIImage imageWithContentsOfFile:file];
+                UIImage *image = [UIImage imageWithContentsOfFile:fileNamePath];
                 
                 if (image)
                     UIImageWriteToSavedPhotosAlbum(image, self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
@@ -1159,11 +1163,9 @@
             
             if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video] && status == PHAuthorizationStatusAuthorized) {
                 
-                [[NSFileManager defaultManager] linkItemAtPath:file toPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNameView] error:nil];
-                
-                if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum([NSTemporaryDirectory() stringByAppendingString:metadata.fileNameView])) {
+                if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(fileNamePath)) {
                     
-                    UISaveVideoAtPathToSavedPhotosAlbum([NSTemporaryDirectory() stringByAppendingString:metadata.fileNameView], self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
+                    UISaveVideoAtPathToSavedPhotosAlbum(fileNamePath, self, @selector(saveSelectedFilesSelector: didFinishSavingWithError: contextInfo:), nil);
                 } else {
                     [appDelegate messageNotification:@"_save_selected_files_" description:@"_file_not_saved_cameraroll_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:k_CCErrorInternalError];
                 }
@@ -1215,7 +1217,7 @@
         // File do not exists on server, remove in local
         if (errorCode == kOCErrorServerPathNotFound || errorCode == kCFURLErrorBadServerResponse) {
             
-            [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, fileID] error:nil];
+            [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorage], fileID] error:nil];
             [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, fileID] error:nil];
             
             if (metadata.directory && serverUrl) {
@@ -1385,7 +1387,6 @@
         metadataForUpload.fileID = [directoryID stringByAppendingString:fileName];
         metadataForUpload.fileName = fileName;
         metadataForUpload.fileNameView = fileName;
-        metadataForUpload.path = appDelegate.directoryUser;
         metadataForUpload.session = session;
         metadataForUpload.sessionSelector = selectorUploadFile;
         metadataForUpload.status = k_metadataStatusWaitUpload;
@@ -2803,7 +2804,7 @@
 
     [[NCManageDatabase sharedInstance] deleteLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
     
-    [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID] error:nil];
+    [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorage], metadata.fileID] error:nil];
     
     [self reloadDatasource:serverUrl];
 }
@@ -3401,22 +3402,8 @@
             NSString *fileID = [NSKeyedUnarchiver unarchiveObjectWithData:dataFileID];
             
             if (fileID) {
-                
-                tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
-            
-                if (metadata) {
-            
-                    tableAccount *account = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", metadata.account]];
-                
-                    if (account) {
-                
-                        NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
-            
-                        if (directoryUser)
-                            if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, fileID]])
-                                return YES;
-                    }
-                }
+                if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorage], fileID]])
+                    return YES;
             }
         }
             
@@ -3440,32 +3427,8 @@
             NSString *fileID = [NSKeyedUnarchiver unarchiveObjectWithData:dataFileID];
 
             if (fileID) {
-            
-                tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
-            
-                if (metadata) {
-            
-                    tableAccount *account = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", metadata.account]];
-
-                    if (account) {
-                
-                        NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
-            
-                        if (directoryUser) {
-                            if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, fileID]]) {
-                                isValid = YES;
-                            } else {
-                                isValid = NO;
-                                break;
-                            }
-                        } else {
-                            isValid = NO;
-                            break;
-                        }
-                    } else {
-                        isValid = NO;
-                        break;
-                    }
+                if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorage], fileID]]) {
+                    isValid = YES;
                 } else {
                     isValid = NO;
                     break;
@@ -3490,7 +3453,7 @@
     UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
     pasteboard.items = [[NSArray alloc] init];
     
-    if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser,_metadata.fileID]]) {
+    if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageFileID:_metadata.fileID],_metadata.fileNameView]]) {
         
         [self copyFileToPasteboard:_metadata];
         
@@ -3523,7 +3486,7 @@
     
     for (tableMetadata *metadata in selectedMetadatas) {
         
-        if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID]]) {
+        if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryProviderStorageFileID:_metadata.fileID],_metadata.fileNameView]]) {
             
             [self copyFileToPasteboard:metadata];
             
@@ -3598,40 +3561,27 @@
         
         if (metadata) {
             
-            tableAccount *account = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", metadata.account]];
-            
-            if (account) {
+            if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]]) {
                 
-                NSString *directoryUser = [CCUtility getDirectoryActiveUser:account.user activeUrl:account.url];
-                
-                if (directoryUser) {
-                    
-                    if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, fileID]]) {
+                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, timer * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
                         
-                        [CCUtility copyFileAtPath:[NSString stringWithFormat:@"%@/%@", directoryUser, metadata.fileID] toPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileNameView]];
-                        
-                        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, timer * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
-                        
-                            tableMetadata *metadataForUpload = [tableMetadata new];
+                    tableMetadata *metadataForUpload = [tableMetadata new];
                         
-                            metadataForUpload.account = appDelegate.activeAccount;
-                            metadataForUpload.date = [NSDate new];
-                            metadataForUpload.directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:self.serverUrl];
-                            metadataForUpload.fileID = [metadataForUpload.directoryID stringByAppendingString:metadata.fileName];
-                            metadataForUpload.fileName = metadata.fileName;
-                            metadataForUpload.fileNameView = metadata.fileNameView;
-                            metadataForUpload.path = appDelegate.directoryUser;
-                            metadataForUpload.session = k_upload_session;
-                            metadataForUpload.sessionSelector = selectorUploadFile;
-                            metadataForUpload.status = k_metadataStatusWaitUpload;
+                    metadataForUpload.account = appDelegate.activeAccount;
+                    metadataForUpload.date = [NSDate new];
+                    metadataForUpload.directoryID = [[NCManageDatabase sharedInstance] getDirectoryID:self.serverUrl];
+                    metadataForUpload.fileID = [metadataForUpload.directoryID stringByAppendingString:metadata.fileName];
+                    metadataForUpload.fileName = metadata.fileName;
+                    metadataForUpload.fileNameView = metadata.fileNameView;
+                    metadataForUpload.session = k_upload_session;
+                    metadataForUpload.sessionSelector = selectorUploadFile;
+                    metadataForUpload.status = k_metadataStatusWaitUpload;
                             
-                            // Add Medtadata for upload
-                            (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
-                        });
+                    // Add Medtadata for upload
+                    (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForUpload];
+                });
                         
-                        timer += 0.1;
-                    }
-                }
+                timer += 0.1;
             }
         }
     }
@@ -3848,7 +3798,7 @@
         [self performSelector:@selector(deleteFile) withObject:nil];
     }]];
     
-    if (localFile || [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, _metadata.fileID]]) {
+    if (localFile || [[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageFileID:_metadata.fileID fileNameView:_metadata.fileNameView]]) {
         [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_remove_local_file_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
             [self performSelector:@selector(removeLocalFile:) withObject:_metadata];
         }]];
@@ -4695,7 +4645,7 @@
         [dateFormatter setDateStyle:NSDateFormatterShortStyle];
         [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
         
-        if (localFile && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID]])
+        if (localFile && [[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]])
             cell.local.image = [UIImage imageNamed:@"local"];
         else
             cell.local.image = nil;
@@ -5123,7 +5073,7 @@
     if (_metadata.directory == NO) {
         
         // se il file esiste andiamo direttamente al delegato altrimenti carichiamolo
-        if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, _metadata.fileID]]) {
+        if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageFileID:_metadata.fileID fileNameView:_metadata.fileNameView]]) {
             
             [self downloadFileSuccessFailure:_metadata.fileName fileID:_metadata.fileID serverUrl:serverUrl selector:selectorLoadFileView selectorPost:@"" errorMessage:@"" errorCode:0];
             

+ 2 - 2
iOSClient/Networking/CCNetworking.m

@@ -501,7 +501,7 @@
     // File exists ?
     tableLocalFile *localfile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
         
-    if (localfile != nil && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", _directoryUser, metadata.fileID]]) {
+    if (localfile != nil && [[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]]) {
             
         [[NCManageDatabase sharedInstance] setMetadataSession:@"" sessionError:@"" sessionSelector:@"" sessionSelectorPost:@"" sessionTaskIdentifier:k_taskIdentifierDone status:k_metadataStatusNormal predicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
             
@@ -612,7 +612,7 @@
     
     if (httpResponse.statusCode >= 200 && httpResponse.statusCode < 300) {
         
-        NSString *destinationFilePath = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryActiveUser:_activeUser activeUrl:_activeUrl], metadata.fileID];
+        NSString *destinationFilePath = [CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView];
         NSURL *destinationURL = [NSURL fileURLWithPath:destinationFilePath];
         
         [[NSFileManager defaultManager] removeItemAtURL:destinationURL error:NULL];

+ 2 - 4
iOSClient/Photos/CCPhotos.m

@@ -368,10 +368,8 @@
     
     for (tableMetadata *metadata in _selectedMetadatas) {
     
-        NSString *fileNamePath = [NSTemporaryDirectory() stringByAppendingString:metadata.fileName];
-        
-        [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID] toPath:fileNamePath error:nil];
-        
+        NSString *fileNamePath = [CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView];
+                
         if ([[NSFileManager defaultManager] fileExistsAtPath:fileNamePath]) {
             
             if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {

+ 2 - 2
iOSClient/Synchronize/CCSynchronize.m

@@ -142,7 +142,7 @@
         // delete metadata not present
         for (tableMetadata *metadata in metadatasNotPresents) {
         
-            [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID] error:nil];
+            [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID] error:nil];
             [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, metadata.fileID] error:nil];
             
             if (metadata.directory && metadataNet.serverUrl) {
@@ -357,7 +357,7 @@
         if (changeRev) {
             
             // remove file and ico
-            [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", appDelegate.directoryUser, metadata.fileID] error:nil];
+            [[NSFileManager defaultManager] removeItemAtPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID] error:nil];
             [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, metadata.fileID] error:nil];
             
             [metadatas addObject:metadata];

+ 1 - 1
iOSClient/Text/NCText.swift

@@ -60,7 +60,7 @@ class NCText: UIViewController, UITextViewDelegate {
         if let metadata = metadata {
             
             loadText = ""
-            let path = "\(appDelegate.directoryUser!)/\(metadata.fileID)"
+            let path = CCUtility.getDirectoryProviderStorageFileID(metadata.fileID, fileNameView: metadata.fileNameView)!
             let data = NSData(contentsOfFile: path)
             
             if let data = data {

+ 2 - 0
iOSClient/Utility/CCUtility.h

@@ -171,6 +171,8 @@
 + (NSString *)getDirectoryAudio;
 + (NSString *)getDirectoryCerificates;
 + (NSString *)getDirectoryProviderStorage;
++ (NSString *)getDirectoryProviderStorageFileID:(NSString *)fileID;
++ (NSString *)getDirectoryProviderStorageFileID:(NSString *)fileID fileNameView:(NSString *)fileNameView;
 
 + (NSString *)getTitleSectionDate:(NSDate *)date;
 

+ 14 - 0
iOSClient/Utility/CCUtility.m

@@ -811,6 +811,20 @@
     return dir;
 }
 
++ (NSString *)getDirectoryProviderStorageFileID:(NSString *)fileID
+{
+    [[NSFileManager defaultManager] createDirectoryAtPath:[NSString stringWithFormat:@"%@/%@", [self getDirectoryProviderStorage], fileID] withIntermediateDirectories:YES attributes:nil error:nil];
+    
+    return [NSString stringWithFormat:@"%@/%@", [self getDirectoryProviderStorage], fileID];
+}
+
++ (NSString *)getDirectoryProviderStorageFileID:(NSString *)fileID fileNameView:(NSString *)fileNameView
+{
+    [[NSFileManager defaultManager] createDirectoryAtPath:[NSString stringWithFormat:@"%@/%@", [self getDirectoryProviderStorage], fileID] withIntermediateDirectories:YES attributes:nil error:nil];
+
+    return [NSString stringWithFormat:@"%@/%@/%@", [self getDirectoryProviderStorage], fileID, fileNameView];
+}
+
 + (NSString *)getTitleSectionDate:(NSDate *)date
 {
     NSString * title;