marinofaggiana 4 years ago
parent
commit
ee7c43284a
2 changed files with 24 additions and 17 deletions
  1. 17 6
      iOSClient/Networking/NCNetworking.swift
  2. 7 11
      iOSClient/Utility/CCUtility.m

+ 17 - 6
iOSClient/Networking/NCNetworking.swift

@@ -295,10 +295,15 @@ import NCCommunication
     
     @objc func deleteMetadata(_ metadata: tableMetadata, user: String, userID: String, password: String, url: String, completion: @escaping (_ errorCode: Int, _ errorDescription: String)->()) {
                 
-        let directory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", metadata.account, metadata.serverUrl))
+        let isDirectoryEncrypted = CCUtility.isFolderEncrypted(metadata.serverUrl, e2eEncrypted: metadata.e2eEncrypted, account: metadata.account)
+            
+        if isDirectoryEncrypted {
+            
+            if let directory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", metadata.account, metadata.serverUrl)) {
+                
+                self.deleteMetadataE2EE(metadata, directory: directory, user: user, userID: userID, password: password, url: url, completion: completion)
+            }
             
-        if directory != nil && directory?.e2eEncrypted == true {
-            self.deleteMetadataE2EE(metadata, directory: directory!, user: user, userID: userID, password: password, url: url, completion: completion)
         } else {
             // Verify Live Photo
             if let metadataMov = NCUtility.sharedInstance.hasMOV(metadata: metadata) {
@@ -392,11 +397,17 @@ import NCCommunication
     
     @objc func renameMetadata(_ metadata: tableMetadata, fileNameNew: String, user: String, userID: String, password: String, url: String, viewController: UIViewController?, completion: @escaping (_ errorCode: Int, _ errorDescription: String?)->()) {
         
-        let directory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", metadata.account, metadata.serverUrl))
+        let isDirectoryEncrypted = CCUtility.isFolderEncrypted(metadata.serverUrl, e2eEncrypted: metadata.e2eEncrypted, account: metadata.account)
         
-        if directory != nil && directory!.e2eEncrypted {
-            renameMetadataE2EE(metadata, fileNameNew: fileNameNew, directory: directory!, user: user, userID: userID, password: password, url: url, completion: completion)
+        if isDirectoryEncrypted {
+            
+            if let directory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", metadata.account, metadata.serverUrl)) {
+                
+                 renameMetadataE2EE(metadata, fileNameNew: fileNameNew, directory: directory, user: user, userID: userID, password: password, url: url, completion: completion)
+            }
+    
         } else {
+            
             renameMetadataPlain(metadata, fileNameNew: fileNameNew, completion: completion)
         }
     }

+ 7 - 11
iOSClient/Utility/CCUtility.m

@@ -1431,23 +1431,19 @@
 + (BOOL)isFolderEncrypted:(NSString *)serverUrl e2eEncrypted:(BOOL)e2eEncrypted account:(NSString *)account
 {
     
-    /*
-    NSArray *directories = [[NCManageDatabase sharedInstance] getTablesDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND e2eEncrypted == 1 AND serverUrl BEGINSWITH %@", account, serverUrl] sorted:@"serverUrl" ascending:false];
-    for (tableDirectory *directory in directories) {
-        if ([serverUrl containsString:directory.serverUrl])
-            return true;
-
-    */
-    
     if (e2eEncrypted) {
         
         return true;
         
     } else {
         
-        tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND e2eEncrypted == 1 AND serverUrl == %@", account, serverUrl]];
-        if (directory != nil) return true;
-        else return false;
+        NSArray *directories = [[NCManageDatabase sharedInstance] getTablesDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND e2eEncrypted == 1 AND serverUrl BEGINSWITH %@", account, serverUrl] sorted:@"serverUrl" ascending:false];
+        for (tableDirectory *directory in directories) {
+            if ([serverUrl containsString:directory.serverUrl])
+                return true;
+        }
+        
+        return false;
     }
 }