marinofaggiana 4 年之前
父节点
当前提交
ab15fb5b59

+ 2 - 2
iOSClient/Data/NCManageDatabase.swift

@@ -2208,7 +2208,7 @@ class NCManageDatabase: NSObject {
             serverUrl = ".."
         } else {
             fileName = (serverUrl as NSString).lastPathComponent
-            serverUrl = CCUtility.deletingLastPathComponent(fromServerUrl: serverUrl)
+            serverUrl = NCUtility.shared.deletingLastPathComponent(serverUrl: serverUrl, urlBase: urlBase, account: account)
         }
         
         guard let result = realm.objects(tableMetadata.self).filter("account == %@ AND serverUrl == %@ AND fileName == %@", account, serverUrl, fileName).first else { return nil }
@@ -2436,7 +2436,7 @@ class NCManageDatabase: NSObject {
             
             let addObject = tableShare()
             let fullPath = NCUtility.shared.getHomeServer(urlBase: urlBase, account: account) + share.path
-            let serverUrl = CCUtility.deletingLastPathComponent(fromServerUrl: fullPath)!
+            let serverUrl = NCUtility.shared.deletingLastPathComponent(serverUrl:fullPath, urlBase: urlBase, account: account)
             let fileName = NSString(string: fullPath).lastPathComponent
                         
             addObject.account = account

+ 2 - 2
iOSClient/Main/Colleaction Common/NCCollectionCommon.swift

@@ -151,7 +151,7 @@ class NCCollectionCommon: NSObject, NCSelectDelegate {
             listViewController.insert(vc, at: 0)
             
             if serverUrl != homeUrl {
-                serverUrl = CCUtility.deletingLastPathComponent(fromServerUrl: serverUrl)
+                serverUrl = NCUtility.shared.deletingLastPathComponent(serverUrl: serverUrl, urlBase: appDelegate.urlBase, account: appDelegate.account)
             } else {
                 break
             }
@@ -194,7 +194,7 @@ class NCCollectionCommon: NSObject, NCSelectDelegate {
             listViewController.insert(vc, at: 0)
             
             if serverUrl != homeUrl {
-                serverUrl = CCUtility.deletingLastPathComponent(fromServerUrl: serverUrl)
+                serverUrl = NCUtility.shared.deletingLastPathComponent(serverUrl: serverUrl, urlBase: appDelegate.urlBase, account: appDelegate.account)
             } else {
                 break
             }

+ 1 - 1
iOSClient/Settings/CCManageAutoUpload.m

@@ -495,7 +495,7 @@
         
         // Settings new folder Automatatic upload
         [[NCManageDatabase sharedInstance] setAccountAutoUploadFileName:serverUrl.lastPathComponent];
-        [[NCManageDatabase sharedInstance] setAccountAutoUploadDirectory:[CCUtility deletingLastPathComponentFromServerUrl:serverUrl] urlBase:appDelegate.urlBase account:appDelegate.account];
+        [[NCManageDatabase sharedInstance] setAccountAutoUploadDirectory:[[NCUtility shared] deletingLastPathComponentWithServerUrl:serverUrl urlBase:appDelegate.urlBase account:appDelegate.account] urlBase:appDelegate.urlBase account:appDelegate.account];
     }
 }
 

+ 0 - 1
iOSClient/Utility/CCUtility.h

@@ -230,7 +230,6 @@
 + (void)removeFileAtPath:(NSString *)atPath;
 + (void)createDirectoryAtPath:(NSString *)atPath;
 
-+ (NSString *)deletingLastPathComponentFromServerUrl:(NSString *)serverUrl;
 + (NSString *)returnPathfromServerUrl:(NSString *)serverUrl urlBase:(NSString *)urlBase account:(NSString *)account;
 + (NSString *)returnFileNamePathFromFileName:(NSString *)metadataFileName serverUrl:(NSString *)serverUrl urlBase:(NSString *)urlBase account:(NSString *)account;
 + (NSArray *)createNameSubFolder:(NSArray *)assets;

+ 2 - 10
iOSClient/Utility/CCUtility.m

@@ -1269,14 +1269,6 @@
     [[NSFileManager defaultManager] createDirectoryAtPath:atPath withIntermediateDirectories:true attributes:nil error:nil];
 }
 
-+ (NSString *)deletingLastPathComponentFromServerUrl:(NSString *)serverUrl
-{
-    NSURL *url = [[NSURL URLWithString:[serverUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]]] URLByDeletingLastPathComponent];
-    NSString *pather = [[url absoluteString] stringByRemovingPercentEncoding];
-    
-    return [pather substringToIndex: [pather length] - 1];
-}
-
 + (NSString *)returnPathfromServerUrl:(NSString *)serverUrl urlBase:(NSString *)urlBase account:(NSString *)account
 {
     NSString *homeServer = [[NCUtility shared] getHomeServerWithUrlBase:urlBase account:account];
@@ -1579,11 +1571,11 @@
        
         tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", account, serverUrl]];
         
-        while (directory != nil) {
+        while (![directory.serverUrl isEqualToString:home]) {
             if (directory.e2eEncrypted == true) {
                 return true;
             }
-            serverUrl = [CCUtility deletingLastPathComponentFromServerUrl:serverUrl];
+            serverUrl = [[NCUtility shared] deletingLastPathComponentWithServerUrl:serverUrl urlBase:urlBase account:account];
             directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", account, serverUrl]];
         }
         

+ 7 - 0
iOSClient/Utility/NCUtility.swift

@@ -47,6 +47,13 @@ class NCUtility: NSObject {
         return urlBase + "/" + self.getWebDAV(account: account)
     }
     
+    @objc func deletingLastPathComponent(serverUrl: String, urlBase: String, account: String) -> String {
+        if getHomeServer(urlBase: urlBase, account: account) == serverUrl { return serverUrl }
+        let fileName = (serverUrl as NSString).lastPathComponent
+        let serverUrl = serverUrl.replacingOccurrences(of: "/"+fileName, with: "", options: String.CompareOptions.backwards, range: nil)
+        return serverUrl
+    }
+    
     @objc func createFileName(_ fileName: String, serverUrl: String, account: String) -> String {
         
         var resultFileName = fileName