Bladeren bron

Merge pull request #2201 from nextcloud/develop

V 4.5 - final
Marino Faggiana 2 jaren geleden
bovenliggende
commit
6b7e7aee36

+ 2 - 2
Nextcloud.xcodeproj/project.pbxproj

@@ -3607,7 +3607,7 @@
 				CLANG_WARN_UNREACHABLE_CODE = YES;
 				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
 				COPY_PHASE_STRIP = NO;
-				CURRENT_PROJECT_VERSION = 18;
+				CURRENT_PROJECT_VERSION = 20;
 				DEVELOPMENT_TEAM = NKUJUXUJ3B;
 				ENABLE_STRICT_OBJC_MSGSEND = YES;
 				ENABLE_TESTABILITY = YES;
@@ -3670,7 +3670,7 @@
 				CLANG_WARN_UNREACHABLE_CODE = YES;
 				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
 				COPY_PHASE_STRIP = NO;
-				CURRENT_PROJECT_VERSION = 18;
+				CURRENT_PROJECT_VERSION = 20;
 				DEVELOPMENT_TEAM = NKUJUXUJ3B;
 				ENABLE_STRICT_OBJC_MSGSEND = YES;
 				ENABLE_TESTABILITY = YES;

+ 3 - 1
iOSClient/Data/NCManageDatabase+Metadata.swift

@@ -680,7 +680,9 @@ extension NCManageDatabase {
             serverUrl = ".."
         } else {
             fileName = (serverUrl as NSString).lastPathComponent
-            serverUrl = NCUtilityFileSystem.shared.deletingLastPathComponent(account: account, serverUrl: serverUrl)
+            if let path = NCUtilityFileSystem.shared.deleteLastPath(serverUrlPath: serverUrl) {
+                serverUrl = path
+            }
         }
 
         guard let result = realm.objects(tableMetadata.self).filter("account == %@ AND serverUrl == %@ AND fileName == %@", account, serverUrl, fileName).first else { return nil }

+ 59 - 52
iOSClient/Data/NCManageDatabase.swift

@@ -1377,60 +1377,67 @@ class NCManageDatabase: NSObject {
     @objc func addShare(urlBase: String, account: String, shares: [NKShare]) {
 
         let realm = try! Realm()
-        realm.beginWrite()
-
-        for share in shares {
-
-            let addObject = tableShare()
-            let fullPath = NCUtilityFileSystem.shared.getHomeServer(account: account) + share.path
-            let serverUrl = NCUtilityFileSystem.shared.deletingLastPathComponent(account: account, serverUrl: fullPath)
-            let fileName = NSString(string: fullPath).lastPathComponent
-
-            addObject.account = account
-            addObject.fileName = fileName
-            addObject.serverUrl = serverUrl
-
-            addObject.canEdit = share.canEdit
-            addObject.canDelete = share.canDelete
-            addObject.date = share.date
-            addObject.displaynameFileOwner = share.displaynameFileOwner
-            addObject.displaynameOwner = share.displaynameOwner
-            addObject.expirationDate =  share.expirationDate
-            addObject.fileParent = share.fileParent
-            addObject.fileSource = share.fileSource
-            addObject.fileTarget = share.fileTarget
-            addObject.hideDownload = share.hideDownload
-            addObject.idShare = share.idShare
-            addObject.itemSource = share.itemSource
-            addObject.itemType = share.itemType
-            addObject.label = share.label
-            addObject.mailSend = share.mailSend
-            addObject.mimeType = share.mimeType
-            addObject.note = share.note
-            addObject.parent = share.parent
-            addObject.password = share.password
-            addObject.path = share.path
-            addObject.permissions = share.permissions
-            addObject.sendPasswordByTalk = share.sendPasswordByTalk
-            addObject.shareType = share.shareType
-            addObject.shareWith = share.shareWith
-            addObject.shareWithDisplayname = share.shareWithDisplayname
-            addObject.storage = share.storage
-            addObject.storageId = share.storageId
-            addObject.token = share.token
-            addObject.uidOwner = share.uidOwner
-            addObject.uidFileOwner = share.uidFileOwner
-            addObject.url = share.url
-            addObject.userClearAt = share.userClearAt
-            addObject.userIcon = share.userIcon
-            addObject.userMessage = share.userMessage
-            addObject.userStatus = share.userStatus
-
-            realm.add(addObject, update: .all)
-        }
+        let home = NCUtilityFileSystem.shared.getHomeServer(account: account)
 
         do {
-            try realm.commitWrite()
+            try realm.safeWrite {
+
+                let results = realm.objects(tableShare.self).filter("account == %@", account)
+                realm.delete(results)
+
+                for share in shares {
+
+                    let serverUrlPath = home + share.path
+                    guard let serverUrl = NCUtilityFileSystem.shared.deleteLastPath(serverUrlPath: serverUrlPath, home: home) else {
+                        continue
+                    }
+                    let fileName = NSString(string: serverUrlPath).lastPathComponent
+
+                    let object = tableShare()
+
+                    object.account = account
+                    object.fileName = fileName
+                    object.serverUrl = serverUrl
+
+                    object.canEdit = share.canEdit
+                    object.canDelete = share.canDelete
+                    object.date = share.date
+                    object.displaynameFileOwner = share.displaynameFileOwner
+                    object.displaynameOwner = share.displaynameOwner
+                    object.expirationDate =  share.expirationDate
+                    object.fileParent = share.fileParent
+                    object.fileSource = share.fileSource
+                    object.fileTarget = share.fileTarget
+                    object.hideDownload = share.hideDownload
+                    object.idShare = share.idShare
+                    object.itemSource = share.itemSource
+                    object.itemType = share.itemType
+                    object.label = share.label
+                    object.mailSend = share.mailSend
+                    object.mimeType = share.mimeType
+                    object.note = share.note
+                    object.parent = share.parent
+                    object.password = share.password
+                    object.path = share.path
+                    object.permissions = share.permissions
+                    object.sendPasswordByTalk = share.sendPasswordByTalk
+                    object.shareType = share.shareType
+                    object.shareWith = share.shareWith
+                    object.shareWithDisplayname = share.shareWithDisplayname
+                    object.storage = share.storage
+                    object.storageId = share.storageId
+                    object.token = share.token
+                    object.uidOwner = share.uidOwner
+                    object.uidFileOwner = share.uidFileOwner
+                    object.url = share.url
+                    object.userClearAt = share.userClearAt
+                    object.userIcon = share.userIcon
+                    object.userMessage = share.userMessage
+                    object.userStatus = share.userStatus
+
+                    realm.add(object)
+                }
+            }
         } catch let error {
             NKCommon.shared.writeLog("Could not write to database: \(error)")
         }

+ 3 - 1
iOSClient/Main/NCFunctionCenter.swift

@@ -573,7 +573,9 @@ import Photos
             listViewController.insert(vc, at: 0)
 
             if serverUrl != homeUrl {
-                serverUrl = NCUtilityFileSystem.shared.deletingLastPathComponent(account: appDelegate.account, serverUrl: serverUrl)
+                if let path = NCUtilityFileSystem.shared.deleteLastPath(serverUrlPath: serverUrl) {
+                    serverUrl = path
+                }
             } else {
                 break
             }

+ 2 - 1
iOSClient/Networking/NCService.swift

@@ -197,9 +197,10 @@ class NCService: NSObject {
             if isFilesSharingEnabled {
                 NextcloudKit.shared.readShares(parameters: NKShareParameter(), options: options) { account, shares, data, error in
                     if error == .success {
-                        NCManageDatabase.shared.deleteTableShare(account: account)
                         if let shares = shares, !shares.isEmpty {
                             NCManageDatabase.shared.addShare(urlBase: self.appDelegate.urlBase, account: account, shares: shares)
+                        } else {
+                            NCManageDatabase.shared.deleteTableShare(account: account)
                         }
                         self.appDelegate.shares = NCManageDatabase.shared.getTableShares(account: account)
                     }

+ 7 - 3
iOSClient/Settings/CCManageAutoUpload.m

@@ -394,8 +394,9 @@
 - (void)dismissSelectWithServerUrl:(NSString *)serverUrl metadata:(tableMetadata *)metadata type:(NSString *)type items:(NSArray *)items overwrite:(BOOL)overwrite copy:(BOOL)copy move:(BOOL)move
 {
     if (serverUrl != nil) {
-        
-        if ([serverUrl isEqualToString:[[NCUtilityFileSystem shared] getHomeServerWithAccount:appDelegate.account]]) {
+
+        NSString* home = [[NCUtilityFileSystem shared] getHomeServerWithAccount:appDelegate.account];
+        if ([serverUrl isEqualToString:home]) {
             NKError *error = [[NKError alloc] initWithErrorCode:NCGlobal.shared.errorInternalError errorDescription:@"_autoupload_error_select_folder_"];
             [[NCContentPresenter shared] messageNotification:@"_error_" error:error delay:[[NCGlobal shared] dismissAfterSecond] type:messageTypeError];
             return;
@@ -403,7 +404,10 @@
         
         // Settings new folder Automatatic upload
         [[NCManageDatabase shared] setAccountAutoUploadFileName:serverUrl.lastPathComponent];
-        [[NCManageDatabase shared] setAccountAutoUploadDirectory:[[NCUtilityFileSystem shared] deletingLastPathComponentWithAccount:appDelegate.account serverUrl:serverUrl] urlBase:appDelegate.urlBase account:appDelegate.account];
+        NSString *path = [[NCUtilityFileSystem shared] deleteLastPathWithServerUrlPath:serverUrl home:home];
+        if (path != nil) {
+            [[NCManageDatabase shared] setAccountAutoUploadDirectory:path urlBase:appDelegate.urlBase account:appDelegate.account];
+        }
         // Reload
         [self.tableView reloadData];
     }

+ 4 - 4
iOSClient/Shares/NCShares.swift

@@ -98,10 +98,10 @@ class NCShares: NCCollectionViewCommon {
             }
 
             if error == .success {
-
-                NCManageDatabase.shared.deleteTableShare(account: account)
-                if shares != nil {
-                    NCManageDatabase.shared.addShare(urlBase: self.appDelegate.urlBase, account: account, shares: shares!)
+                if let shares = shares, !shares.isEmpty {
+                    NCManageDatabase.shared.addShare(urlBase: self.appDelegate.urlBase, account: account, shares: shares)
+                } else {
+                    NCManageDatabase.shared.deleteTableShare(account: account)
                 }
                 self.appDelegate.shares = NCManageDatabase.shared.getTableShares(account: account)
                 self.reloadDataSource()

+ 5 - 1
iOSClient/Utility/CCUtility.m

@@ -1356,7 +1356,11 @@
             if (directory.e2eEncrypted == true) {
                 return true;
             }
-            serverUrl = [[NCUtilityFileSystem shared] deletingLastPathComponentWithAccount:account serverUrl:serverUrl];
+            NSString* home = [[NCUtilityFileSystem shared] getHomeServerWithAccount:account];
+            NSString* path = [[NCUtilityFileSystem shared] deleteLastPathWithServerUrlPath:serverUrl home:home];
+            if (path != nil) {
+                serverUrl = path;
+            }
             directory = [[NCManageDatabase shared] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", account, serverUrl]];
         }
         

+ 17 - 5
iOSClient/Utility/NCUtilityFileSystem.swift

@@ -174,12 +174,24 @@ class NCUtilityFileSystem: NSObject {
         return path
     }
 
-    @objc func deletingLastPathComponent(account: String, serverUrl: String) -> String {
+    @objc func deleteLastPath(serverUrlPath: String, home: String? = nil) -> String? {
 
-        if getHomeServer(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
+        var returnString: String?
+
+        if home == serverUrlPath {
+            return serverUrlPath
+        }
+        
+        if let serverUrlPath = serverUrlPath.urlEncoded, let url = URL(string: serverUrlPath) {
+            if let path = url.deletingLastPathComponent().absoluteString.removingPercentEncoding {
+                if path.last == "/" {
+                    returnString = String(path.dropLast())
+                } else {
+                    returnString = path
+                }
+            }
+        }
+        return returnString
     }
 
     @objc func createFileName(_ fileName: String, serverUrl: String, account: String) -> String {