From ecdba3c007990937ac1c219f81955ae27502990e Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Tue, 1 Oct 2024 17:40:45 +0200 Subject: [PATCH 01/23] rename Signed-off-by: Marino Faggiana --- Brand/Database.swift | 2 +- .../NCManageDatabase+Metadata+Session.swift | 24 +++++++++++++++++++ .../Data/NCManageDatabase+Metadata.swift | 3 +++ .../UIAlertController+Extension.swift | 4 ++++ iOSClient/NCGlobal.swift | 1 + iOSClient/Networking/NCNetworking+Task.swift | 12 +++++++++- .../Networking/NCNetworking+WebDAV.swift | 20 ++++++++++++++++ .../en.lproj/Localizable.strings | 1 + iOSClient/Transfers/NCTransfers.swift | 4 ++++ 9 files changed, 69 insertions(+), 2 deletions(-) diff --git a/Brand/Database.swift b/Brand/Database.swift index 7e7dba8c53..53a53f87ea 100644 --- a/Brand/Database.swift +++ b/Brand/Database.swift @@ -26,4 +26,4 @@ import Foundation // Database Realm // let databaseName = "nextcloud.realm" -let databaseSchemaVersion: UInt64 = 359 +let databaseSchemaVersion: UInt64 = 360 diff --git a/iOSClient/Data/NCManageDatabase+Metadata+Session.swift b/iOSClient/Data/NCManageDatabase+Metadata+Session.swift index 1242b6616a..c15fcbb356 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata+Session.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata+Session.swift @@ -189,4 +189,28 @@ extension NCManageDatabase { fileName, sessionTaskIdentifier)) } + + func restoreMetadataServerUrlFileName(ocId: String) { + do { + let realm = try Realm() + try realm.write { + if let result = realm.objects(tableMetadata.self).filter("ocId == %@", ocId).first, + let encodedURLString = result.serveUrlFileName.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), + let url = URL(string: encodedURLString) { + + let lastPathComponent = url.lastPathComponent + let fileName = lastPathComponent.removingPercentEncoding ?? lastPathComponent + + let baseURL = url.deletingLastPathComponent().absoluteString + let serverUrl = baseURL.removingPercentEncoding ?? baseURL + + result.serverUrl = serverUrl + result.fileName = fileName + result.status = NCGlobal.shared.metadataStatusNormal + } + } + } catch let error { + NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Could not write to database: \(error)") + } + } } diff --git a/iOSClient/Data/NCManageDatabase+Metadata.swift b/iOSClient/Data/NCManageDatabase+Metadata.swift index cc84c82589..f86d476458 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata.swift @@ -110,6 +110,7 @@ class tableMetadata: Object { @objc dynamic var richWorkspace: String? @objc dynamic var sceneIdentifier: String? @objc dynamic var serverUrl = "" + @objc dynamic var serveUrlFileName = "" @objc dynamic var session = "" @objc dynamic var sessionDate: Date? @objc dynamic var sessionError = "" @@ -392,6 +393,7 @@ extension NCManageDatabase { metadata.richWorkspace = file.richWorkspace metadata.resourceType = file.resourceType metadata.serverUrl = file.serverUrl + metadata.serveUrlFileName = file.serverUrl + "/" + file.fileName metadata.sharePermissionsCollaborationServices = file.sharePermissionsCollaborationServices for element in file.sharePermissionsCloudMesh { metadata.sharePermissionsCloudMesh.append(element) @@ -514,6 +516,7 @@ extension NCManageDatabase { metadata.ocIdTransfer = ocId metadata.permissions = "RGDNVW" metadata.serverUrl = serverUrl + metadata.serveUrlFileName = serverUrl + "/" + fileName metadata.subline = subline metadata.uploadDate = Date() as NSDate metadata.url = url diff --git a/iOSClient/Extensions/UIAlertController+Extension.swift b/iOSClient/Extensions/UIAlertController+Extension.swift index 9bc5e2d7f8..7cd7f2de67 100644 --- a/iOSClient/Extensions/UIAlertController+Extension.swift +++ b/iOSClient/Extensions/UIAlertController+Extension.swift @@ -212,6 +212,9 @@ extension UIAlertController { NCActivityIndicator.shared.start() + + + /* NCNetworking.shared.renameMetadata(metadata, fileNameNew: newFileName) { error in NCActivityIndicator.shared.stop() @@ -220,6 +223,7 @@ extension UIAlertController { NCContentPresenter().showError(error: error) } } + */ }) // text field is initially empty, no action diff --git a/iOSClient/NCGlobal.swift b/iOSClient/NCGlobal.swift index af15865e8a..13ce261eda 100644 --- a/iOSClient/NCGlobal.swift +++ b/iOSClient/NCGlobal.swift @@ -272,6 +272,7 @@ class NCGlobal: NSObject { let metadataStatusWaitCreateFolder: Int = 10 let metadataStatusWaitDelete: Int = 11 + let metadataStatusWaitRename: Int = 12 let metadataStatusInTransfer = [-1, -2, 1, 2] let metadataStatusFileDown = [-1, -2, -3] diff --git a/iOSClient/Networking/NCNetworking+Task.swift b/iOSClient/Networking/NCNetworking+Task.swift index aabdb1c289..deb1ac7a09 100644 --- a/iOSClient/Networking/NCNetworking+Task.swift +++ b/iOSClient/Networking/NCNetworking+Task.swift @@ -62,6 +62,14 @@ extension NCNetworking { return } + /// RENAME + /// + if metadata.status == global.metadataStatusWaitRename { + database.restoreMetadataServerUrlFileName(ocId: metadata.ocId) + NotificationCenter.default.postOnMainThread(name: self.global.notificationCenterReloadDataSource) + return + } + /// DIRECTORY /// if metadata.status == global.metadataStatusWaitCreateFolder { @@ -125,7 +133,7 @@ extension NCNetworking { } func cancelAllWaitTask() { - let metadatas = database.getMetadatas(predicate: NSPredicate(format: "status IN %@", [global.metadataStatusWaitCreateFolder, global.metadataStatusWaitDelete])) + let metadatas = database.getMetadatas(predicate: NSPredicate(format: "status IN %@", [global.metadataStatusWaitCreateFolder, global.metadataStatusWaitDelete, global.metadataStatusWaitRename])) for metadata in metadatas { if metadata.status == global.metadataStatusWaitDelete { database.setMetadataStatus(ocId: metadata.ocId, status: global.metadataStatusNormal) @@ -135,6 +143,8 @@ extension NCNetworking { database.deleteMetadataOcId(metadata.ocId) utilityFileSystem.removeFile(atPath: utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId)) } + } else if metadata.status == global.metadataStatusWaitRename { + database.restoreMetadataServerUrlFileName(ocId: metadata.ocId) } } NotificationCenter.default.postOnMainThread(name: self.global.notificationCenterReloadDataSource) diff --git a/iOSClient/Networking/NCNetworking+WebDAV.swift b/iOSClient/Networking/NCNetworking+WebDAV.swift index 38266ccc08..e9e00c9f79 100644 --- a/iOSClient/Networking/NCNetworking+WebDAV.swift +++ b/iOSClient/Networking/NCNetworking+WebDAV.swift @@ -479,6 +479,26 @@ extension NCNetworking { } } + func renameMetadata(_ metadata: tableMetadata, fileNameNew: String) { + let permission = utility.permissionsContainsString(metadata.permissions, permissions: NCPermissions().permissionCanRename) + if !metadata.permissions.isEmpty && permission == false { + NCContentPresenter().showInfo(error: NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_no_permission_modify_file_")) + return + } + + /* + if metadata.status == global.metadataStatusWaitCreateFolder { + let metadatas = database.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl BEGINSWITH %@", metadata.account, metadata.serverUrl)) + for metadata in metadatas { + database.deleteMetadataOcId(metadata.ocId) + utilityFileSystem.removeFile(atPath: utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId)) + } + return + } + */ + self.database.setMetadataStatus(ocId: metadata.ocId, status: NCGlobal.shared.metadataStatusWaitDelete) + } + // MARK: - Move func moveMetadata(_ metadata: tableMetadata, serverUrlTo: String, overwrite: Bool) async -> NKError { diff --git a/iOSClient/Supporting Files/en.lproj/Localizable.strings b/iOSClient/Supporting Files/en.lproj/Localizable.strings index 32a55df232..0e1fbf5220 100644 --- a/iOSClient/Supporting Files/en.lproj/Localizable.strings +++ b/iOSClient/Supporting Files/en.lproj/Localizable.strings @@ -608,6 +608,7 @@ "_status_wait_upload_" = "Waiting to upload"; "_status_wait_create_folder_" = "Waiting to create the folder"; "_status_wait_delete_" = "Waiting to delete"; +"_status_wait_rename_" = "Waiting to rename"; "_status_in_upload_" = "In upload"; "_status_uploading_" = "Uploading"; "_status_upload_error_" = "Error, waiting to upload"; diff --git a/iOSClient/Transfers/NCTransfers.swift b/iOSClient/Transfers/NCTransfers.swift index 6b1db2e17f..af71ad1364 100644 --- a/iOSClient/Transfers/NCTransfers.swift +++ b/iOSClient/Transfers/NCTransfers.swift @@ -234,6 +234,10 @@ class NCTransfers: NCCollectionViewCommon, NCTransferCellDelegate { cell.fileStatusImage?.image = utility.loadImage(named: "trash.circle", colors: NCBrandColor.shared.iconImageMultiColors) cell.labelStatus.text = NSLocalizedString("_status_wait_delete_", comment: "") + user cell.labelInfo.text = "" + case NCGlobal.shared.metadataStatusWaitRename: + cell.fileStatusImage?.image = utility.loadImage(named: "a.circle", colors: NCBrandColor.shared.iconImageMultiColors) + cell.labelStatus.text = NSLocalizedString("_status_wait_rename_", comment: "") + user + cell.labelInfo.text = "" case NCGlobal.shared.metadataStatusDownloading: if #available(iOS 17.0, *) { cell.fileStatusImage?.image = utility.loadImage(named: "arrowshape.down.circle", colors: NCBrandColor.shared.iconImageMultiColors) From 7349347b418a97233aae637430d9c9a3d955f984 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Tue, 1 Oct 2024 17:41:45 +0200 Subject: [PATCH 02/23] migration DB Signed-off-by: Marino Faggiana --- iOSClient/Data/NCManageDatabase.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iOSClient/Data/NCManageDatabase.swift b/iOSClient/Data/NCManageDatabase.swift index e8b359035f..2a729cfeea 100644 --- a/iOSClient/Data/NCManageDatabase.swift +++ b/iOSClient/Data/NCManageDatabase.swift @@ -42,7 +42,7 @@ class NCManageDatabase: NSObject { override init() { func migrationSchema(_ migration: Migration, _ oldSchemaVersion: UInt64) { - if oldSchemaVersion < 359 { + if oldSchemaVersion < 360 { migration.deleteData(forType: tableMetadata.className()) migration.enumerateObjects(ofType: tableDirectory.className()) { _, newObject in newObject?["etag"] = "" From 9818ba4b30786d0f5250656158dcb69ca8d40f89 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Tue, 1 Oct 2024 17:44:56 +0200 Subject: [PATCH 03/23] compactDB Signed-off-by: Marino Faggiana --- iOSClient/Data/NCManageDatabase.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/iOSClient/Data/NCManageDatabase.swift b/iOSClient/Data/NCManageDatabase.swift index 2a729cfeea..cac9b29f83 100644 --- a/iOSClient/Data/NCManageDatabase.swift +++ b/iOSClient/Data/NCManageDatabase.swift @@ -51,11 +51,11 @@ class NCManageDatabase: NSObject { } func compactDB(_ totalBytes: Int, _ usedBytes: Int) -> Bool { - // totalBytes refers to the size of the file on disk in bytes (data + free space) - // usedBytes refers to the number of bytes used by data in the file - // Compact if the file is over 100MB in size and less than 50% 'used' - let oneHundredMB = 100 * 1024 * 1024 - return (totalBytes > oneHundredMB) && (Double(usedBytes) / Double(totalBytes)) < 0.5 + let usedPercentage = (Double(usedBytes) / Double(totalBytes)) * 100 + /// Compact the database if more than 25% of the space is free + let shouldCompact = (usedPercentage < 75.0) && (totalBytes > 100 * 1024 * 1024) + + return shouldCompact } var realm: Realm? let dirGroup = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.shared.capabilitiesGroup) From 46265a8a8d2e2b59024ada4a89b94a8bc4bcfa9c Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Tue, 1 Oct 2024 18:12:35 +0200 Subject: [PATCH 04/23] cod Signed-off-by: Marino Faggiana --- .../Data/NCManageDatabase+Metadata.swift | 18 +++++++++++ .../Networking/NCNetworkingProcess.swift | 30 ++++++++++++++----- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/iOSClient/Data/NCManageDatabase+Metadata.swift b/iOSClient/Data/NCManageDatabase+Metadata.swift index f86d476458..ab76ed45c9 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata.swift @@ -635,6 +635,24 @@ extension NCManageDatabase { } } + func renameMetadata(ocId: String) { + do { + let realm = try Realm() + try realm.write { + if let result = realm.objects(tableMetadata.self).filter("ocId == %@", ocId).first { + let resultsType = NextcloudKit.shared.nkCommonInstance.getInternalType(fileName: result.fileName, mimeType: "", directory: result.directory, account: result.account) + + result.iconName = resultsType.iconName + result.contentType = resultsType.mimeType + result.classFile = resultsType.classFile + result.serveUrlFileName = self.utilityFileSystem.stringAppendServerUrl(result.serverUrl, addFileName: result.fileName) + } + } + } catch let error { + NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Could not write to database: \(error)") + } + } + func setMetadataEtagResource(ocId: String, etagResource: String?) { guard let etagResource else { return } diff --git a/iOSClient/Networking/NCNetworkingProcess.swift b/iOSClient/Networking/NCNetworkingProcess.swift index 7a87d0a3d9..ce098c7a6d 100644 --- a/iOSClient/Networking/NCNetworkingProcess.swift +++ b/iOSClient/Networking/NCNetworkingProcess.swift @@ -128,7 +128,7 @@ class NCNetworkingProcess { } @discardableResult - private func start() async -> (counterDownloading: Int, counterUploading: Int) { + private func start() async -> (counterDownloading: Int, counterUploading: Int, counterWebDAV: Int) { let applicationState = await checkApplicationState() let maxConcurrentOperationDownload = NCBrandOptions.shared.maxConcurrentOperationDownload var maxConcurrentOperationUpload = NCBrandOptions.shared.maxConcurrentOperationUpload @@ -148,7 +148,7 @@ class NCNetworkingProcess { NCNetworking.shared.deleteFileOrFolderQueue.addOperation(NCOperationDeleteFileOrFolder(metadata: metadata)) } } - return (counterDownloading, counterUploading) + return (counterDownloading, counterUploading, metadatasWaitDelete.count) } /// ------------------------ FOLDER @@ -162,11 +162,27 @@ class NCNetworkingProcess { let message = String(format: NSLocalizedString("_offlinefolder_error_", comment: ""), serverUrlFileName) NCContentPresenter().messageNotification(message, error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max) } - return (counterDownloading, counterUploading) + return (counterDownloading, counterUploading, metadatasWaitCreateFolder.count) } } } + /// ------------------------ RENAME + /// + if let metadatasWaitRename = self.database.getMetadatas(predicate: NSPredicate(format: "status == %d", global.metadataStatusWaitRename), sortedByKeyPath: "serverUrl", ascending: true), !metadatasWaitRename.isEmpty { + for metadata in metadatasWaitRename { + let serverUrlFileNameSource = metadata.serveUrlFileName + let serverUrlFileNameDestination = metadata.serverUrl + "/" + metadata.fileName + let result = await NCNetworking.shared.moveFileOrFolder(serverUrlFileNameSource: serverUrlFileNameSource, serverUrlFileNameDestination: serverUrlFileNameDestination, overwrite: false, account: metadata.account) + if result.error == .success { + database.renameMetadata(ocId: metadata.ocId) + } else { + database.restoreMetadataServerUrlFileName(ocId: metadata.ocId) + } + } + return (counterDownloading, counterUploading, metadatasWaitRename.count) + } + /// ------------------------ DOWNLOAD /// let limitDownload = maxConcurrentOperationDownload - counterDownloading @@ -195,13 +211,13 @@ class NCNetworkingProcess { /// E2EE - only one for time for metadata in metadatasUploading.unique(map: { $0.serverUrl }) { if metadata.isDirectoryE2EE { - return (counterDownloading, counterUploading) + return (counterDownloading, counterUploading, 0) } } /// CHUNK - only one for time if !metadatasUploading.filter({ $0.chunk > 0 }).isEmpty { - return (counterDownloading, counterUploading) + return (counterDownloading, counterUploading, 0) } for sessionSelector in sessionUploadSelectors where counterUploading < maxConcurrentOperationUpload { @@ -287,7 +303,7 @@ class NCNetworkingProcess { } } - return (counterDownloading, counterUploading) + return (counterDownloading, counterUploading, 0) } private func checkApplicationState() async -> UIApplication.State { @@ -301,7 +317,7 @@ class NCNetworkingProcess { // MARK: - Public - func refreshProcessingTask() async -> (counterDownloading: Int, counterUploading: Int) { + func refreshProcessingTask() async -> (counterDownloading: Int, counterUploading: Int, counterWebDAV: Int) { await withCheckedContinuation { continuation in self.lockQueue.sync { guard !self.hasRun, NCNetworking.shared.isOnline else { return } From 8e506667831dbf3bb0deac5bef345c2f5ad14cea Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Tue, 1 Oct 2024 17:40:45 +0200 Subject: [PATCH 05/23] rename Signed-off-by: Marino Faggiana --- Brand/Database.swift | 2 +- .../NCManageDatabase+Metadata+Session.swift | 24 +++++++++++++++++++ .../Data/NCManageDatabase+Metadata.swift | 3 +++ .../UIAlertController+Extension.swift | 4 ++++ iOSClient/NCGlobal.swift | 1 + iOSClient/Networking/NCNetworking+Task.swift | 12 +++++++++- .../Networking/NCNetworking+WebDAV.swift | 20 ++++++++++++++++ .../en.lproj/Localizable.strings | 1 + iOSClient/Transfers/NCTransfers.swift | 4 ++++ 9 files changed, 69 insertions(+), 2 deletions(-) diff --git a/Brand/Database.swift b/Brand/Database.swift index 7e7dba8c53..53a53f87ea 100644 --- a/Brand/Database.swift +++ b/Brand/Database.swift @@ -26,4 +26,4 @@ import Foundation // Database Realm // let databaseName = "nextcloud.realm" -let databaseSchemaVersion: UInt64 = 359 +let databaseSchemaVersion: UInt64 = 360 diff --git a/iOSClient/Data/NCManageDatabase+Metadata+Session.swift b/iOSClient/Data/NCManageDatabase+Metadata+Session.swift index 1242b6616a..c15fcbb356 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata+Session.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata+Session.swift @@ -189,4 +189,28 @@ extension NCManageDatabase { fileName, sessionTaskIdentifier)) } + + func restoreMetadataServerUrlFileName(ocId: String) { + do { + let realm = try Realm() + try realm.write { + if let result = realm.objects(tableMetadata.self).filter("ocId == %@", ocId).first, + let encodedURLString = result.serveUrlFileName.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), + let url = URL(string: encodedURLString) { + + let lastPathComponent = url.lastPathComponent + let fileName = lastPathComponent.removingPercentEncoding ?? lastPathComponent + + let baseURL = url.deletingLastPathComponent().absoluteString + let serverUrl = baseURL.removingPercentEncoding ?? baseURL + + result.serverUrl = serverUrl + result.fileName = fileName + result.status = NCGlobal.shared.metadataStatusNormal + } + } + } catch let error { + NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Could not write to database: \(error)") + } + } } diff --git a/iOSClient/Data/NCManageDatabase+Metadata.swift b/iOSClient/Data/NCManageDatabase+Metadata.swift index cc84c82589..f86d476458 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata.swift @@ -110,6 +110,7 @@ class tableMetadata: Object { @objc dynamic var richWorkspace: String? @objc dynamic var sceneIdentifier: String? @objc dynamic var serverUrl = "" + @objc dynamic var serveUrlFileName = "" @objc dynamic var session = "" @objc dynamic var sessionDate: Date? @objc dynamic var sessionError = "" @@ -392,6 +393,7 @@ extension NCManageDatabase { metadata.richWorkspace = file.richWorkspace metadata.resourceType = file.resourceType metadata.serverUrl = file.serverUrl + metadata.serveUrlFileName = file.serverUrl + "/" + file.fileName metadata.sharePermissionsCollaborationServices = file.sharePermissionsCollaborationServices for element in file.sharePermissionsCloudMesh { metadata.sharePermissionsCloudMesh.append(element) @@ -514,6 +516,7 @@ extension NCManageDatabase { metadata.ocIdTransfer = ocId metadata.permissions = "RGDNVW" metadata.serverUrl = serverUrl + metadata.serveUrlFileName = serverUrl + "/" + fileName metadata.subline = subline metadata.uploadDate = Date() as NSDate metadata.url = url diff --git a/iOSClient/Extensions/UIAlertController+Extension.swift b/iOSClient/Extensions/UIAlertController+Extension.swift index 9bc5e2d7f8..7cd7f2de67 100644 --- a/iOSClient/Extensions/UIAlertController+Extension.swift +++ b/iOSClient/Extensions/UIAlertController+Extension.swift @@ -212,6 +212,9 @@ extension UIAlertController { NCActivityIndicator.shared.start() + + + /* NCNetworking.shared.renameMetadata(metadata, fileNameNew: newFileName) { error in NCActivityIndicator.shared.stop() @@ -220,6 +223,7 @@ extension UIAlertController { NCContentPresenter().showError(error: error) } } + */ }) // text field is initially empty, no action diff --git a/iOSClient/NCGlobal.swift b/iOSClient/NCGlobal.swift index af15865e8a..13ce261eda 100644 --- a/iOSClient/NCGlobal.swift +++ b/iOSClient/NCGlobal.swift @@ -272,6 +272,7 @@ class NCGlobal: NSObject { let metadataStatusWaitCreateFolder: Int = 10 let metadataStatusWaitDelete: Int = 11 + let metadataStatusWaitRename: Int = 12 let metadataStatusInTransfer = [-1, -2, 1, 2] let metadataStatusFileDown = [-1, -2, -3] diff --git a/iOSClient/Networking/NCNetworking+Task.swift b/iOSClient/Networking/NCNetworking+Task.swift index aabdb1c289..deb1ac7a09 100644 --- a/iOSClient/Networking/NCNetworking+Task.swift +++ b/iOSClient/Networking/NCNetworking+Task.swift @@ -62,6 +62,14 @@ extension NCNetworking { return } + /// RENAME + /// + if metadata.status == global.metadataStatusWaitRename { + database.restoreMetadataServerUrlFileName(ocId: metadata.ocId) + NotificationCenter.default.postOnMainThread(name: self.global.notificationCenterReloadDataSource) + return + } + /// DIRECTORY /// if metadata.status == global.metadataStatusWaitCreateFolder { @@ -125,7 +133,7 @@ extension NCNetworking { } func cancelAllWaitTask() { - let metadatas = database.getMetadatas(predicate: NSPredicate(format: "status IN %@", [global.metadataStatusWaitCreateFolder, global.metadataStatusWaitDelete])) + let metadatas = database.getMetadatas(predicate: NSPredicate(format: "status IN %@", [global.metadataStatusWaitCreateFolder, global.metadataStatusWaitDelete, global.metadataStatusWaitRename])) for metadata in metadatas { if metadata.status == global.metadataStatusWaitDelete { database.setMetadataStatus(ocId: metadata.ocId, status: global.metadataStatusNormal) @@ -135,6 +143,8 @@ extension NCNetworking { database.deleteMetadataOcId(metadata.ocId) utilityFileSystem.removeFile(atPath: utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId)) } + } else if metadata.status == global.metadataStatusWaitRename { + database.restoreMetadataServerUrlFileName(ocId: metadata.ocId) } } NotificationCenter.default.postOnMainThread(name: self.global.notificationCenterReloadDataSource) diff --git a/iOSClient/Networking/NCNetworking+WebDAV.swift b/iOSClient/Networking/NCNetworking+WebDAV.swift index 38266ccc08..e9e00c9f79 100644 --- a/iOSClient/Networking/NCNetworking+WebDAV.swift +++ b/iOSClient/Networking/NCNetworking+WebDAV.swift @@ -479,6 +479,26 @@ extension NCNetworking { } } + func renameMetadata(_ metadata: tableMetadata, fileNameNew: String) { + let permission = utility.permissionsContainsString(metadata.permissions, permissions: NCPermissions().permissionCanRename) + if !metadata.permissions.isEmpty && permission == false { + NCContentPresenter().showInfo(error: NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_no_permission_modify_file_")) + return + } + + /* + if metadata.status == global.metadataStatusWaitCreateFolder { + let metadatas = database.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl BEGINSWITH %@", metadata.account, metadata.serverUrl)) + for metadata in metadatas { + database.deleteMetadataOcId(metadata.ocId) + utilityFileSystem.removeFile(atPath: utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId)) + } + return + } + */ + self.database.setMetadataStatus(ocId: metadata.ocId, status: NCGlobal.shared.metadataStatusWaitDelete) + } + // MARK: - Move func moveMetadata(_ metadata: tableMetadata, serverUrlTo: String, overwrite: Bool) async -> NKError { diff --git a/iOSClient/Supporting Files/en.lproj/Localizable.strings b/iOSClient/Supporting Files/en.lproj/Localizable.strings index 32a55df232..0e1fbf5220 100644 --- a/iOSClient/Supporting Files/en.lproj/Localizable.strings +++ b/iOSClient/Supporting Files/en.lproj/Localizable.strings @@ -608,6 +608,7 @@ "_status_wait_upload_" = "Waiting to upload"; "_status_wait_create_folder_" = "Waiting to create the folder"; "_status_wait_delete_" = "Waiting to delete"; +"_status_wait_rename_" = "Waiting to rename"; "_status_in_upload_" = "In upload"; "_status_uploading_" = "Uploading"; "_status_upload_error_" = "Error, waiting to upload"; diff --git a/iOSClient/Transfers/NCTransfers.swift b/iOSClient/Transfers/NCTransfers.swift index 598ad2d883..d88e239fae 100644 --- a/iOSClient/Transfers/NCTransfers.swift +++ b/iOSClient/Transfers/NCTransfers.swift @@ -234,6 +234,10 @@ class NCTransfers: NCCollectionViewCommon, NCTransferCellDelegate { cell.fileStatusImage?.image = utility.loadImage(named: "trash.circle", colors: NCBrandColor.shared.iconImageMultiColors) cell.labelStatus.text = NSLocalizedString("_status_wait_delete_", comment: "") + user cell.labelInfo.text = "" + case NCGlobal.shared.metadataStatusWaitRename: + cell.fileStatusImage?.image = utility.loadImage(named: "a.circle", colors: NCBrandColor.shared.iconImageMultiColors) + cell.labelStatus.text = NSLocalizedString("_status_wait_rename_", comment: "") + user + cell.labelInfo.text = "" case NCGlobal.shared.metadataStatusDownloading: if #available(iOS 17.0, *) { cell.fileStatusImage?.image = utility.loadImage(named: "arrowshape.down.circle", colors: NCBrandColor.shared.iconImageMultiColors) From 366a3fcdbe312daae7eeb50a8fc7b7d7f1791add Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Tue, 1 Oct 2024 17:41:45 +0200 Subject: [PATCH 06/23] migration DB Signed-off-by: Marino Faggiana --- iOSClient/Data/NCManageDatabase.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iOSClient/Data/NCManageDatabase.swift b/iOSClient/Data/NCManageDatabase.swift index e8b359035f..2a729cfeea 100644 --- a/iOSClient/Data/NCManageDatabase.swift +++ b/iOSClient/Data/NCManageDatabase.swift @@ -42,7 +42,7 @@ class NCManageDatabase: NSObject { override init() { func migrationSchema(_ migration: Migration, _ oldSchemaVersion: UInt64) { - if oldSchemaVersion < 359 { + if oldSchemaVersion < 360 { migration.deleteData(forType: tableMetadata.className()) migration.enumerateObjects(ofType: tableDirectory.className()) { _, newObject in newObject?["etag"] = "" From 1c065117ecec10123a6b983022d1b56c06b9f478 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Tue, 1 Oct 2024 17:44:56 +0200 Subject: [PATCH 07/23] compactDB Signed-off-by: Marino Faggiana --- iOSClient/Data/NCManageDatabase.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/iOSClient/Data/NCManageDatabase.swift b/iOSClient/Data/NCManageDatabase.swift index 2a729cfeea..cac9b29f83 100644 --- a/iOSClient/Data/NCManageDatabase.swift +++ b/iOSClient/Data/NCManageDatabase.swift @@ -51,11 +51,11 @@ class NCManageDatabase: NSObject { } func compactDB(_ totalBytes: Int, _ usedBytes: Int) -> Bool { - // totalBytes refers to the size of the file on disk in bytes (data + free space) - // usedBytes refers to the number of bytes used by data in the file - // Compact if the file is over 100MB in size and less than 50% 'used' - let oneHundredMB = 100 * 1024 * 1024 - return (totalBytes > oneHundredMB) && (Double(usedBytes) / Double(totalBytes)) < 0.5 + let usedPercentage = (Double(usedBytes) / Double(totalBytes)) * 100 + /// Compact the database if more than 25% of the space is free + let shouldCompact = (usedPercentage < 75.0) && (totalBytes > 100 * 1024 * 1024) + + return shouldCompact } var realm: Realm? let dirGroup = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.shared.capabilitiesGroup) From 404ee9d41f3f60bf06291e24ffdf1703bd928084 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Tue, 1 Oct 2024 18:12:35 +0200 Subject: [PATCH 08/23] cod Signed-off-by: Marino Faggiana --- .../Data/NCManageDatabase+Metadata.swift | 18 +++++++++++ .../Networking/NCNetworkingProcess.swift | 30 ++++++++++++++----- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/iOSClient/Data/NCManageDatabase+Metadata.swift b/iOSClient/Data/NCManageDatabase+Metadata.swift index f86d476458..ab76ed45c9 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata.swift @@ -635,6 +635,24 @@ extension NCManageDatabase { } } + func renameMetadata(ocId: String) { + do { + let realm = try Realm() + try realm.write { + if let result = realm.objects(tableMetadata.self).filter("ocId == %@", ocId).first { + let resultsType = NextcloudKit.shared.nkCommonInstance.getInternalType(fileName: result.fileName, mimeType: "", directory: result.directory, account: result.account) + + result.iconName = resultsType.iconName + result.contentType = resultsType.mimeType + result.classFile = resultsType.classFile + result.serveUrlFileName = self.utilityFileSystem.stringAppendServerUrl(result.serverUrl, addFileName: result.fileName) + } + } + } catch let error { + NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Could not write to database: \(error)") + } + } + func setMetadataEtagResource(ocId: String, etagResource: String?) { guard let etagResource else { return } diff --git a/iOSClient/Networking/NCNetworkingProcess.swift b/iOSClient/Networking/NCNetworkingProcess.swift index 7a87d0a3d9..ce098c7a6d 100644 --- a/iOSClient/Networking/NCNetworkingProcess.swift +++ b/iOSClient/Networking/NCNetworkingProcess.swift @@ -128,7 +128,7 @@ class NCNetworkingProcess { } @discardableResult - private func start() async -> (counterDownloading: Int, counterUploading: Int) { + private func start() async -> (counterDownloading: Int, counterUploading: Int, counterWebDAV: Int) { let applicationState = await checkApplicationState() let maxConcurrentOperationDownload = NCBrandOptions.shared.maxConcurrentOperationDownload var maxConcurrentOperationUpload = NCBrandOptions.shared.maxConcurrentOperationUpload @@ -148,7 +148,7 @@ class NCNetworkingProcess { NCNetworking.shared.deleteFileOrFolderQueue.addOperation(NCOperationDeleteFileOrFolder(metadata: metadata)) } } - return (counterDownloading, counterUploading) + return (counterDownloading, counterUploading, metadatasWaitDelete.count) } /// ------------------------ FOLDER @@ -162,11 +162,27 @@ class NCNetworkingProcess { let message = String(format: NSLocalizedString("_offlinefolder_error_", comment: ""), serverUrlFileName) NCContentPresenter().messageNotification(message, error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max) } - return (counterDownloading, counterUploading) + return (counterDownloading, counterUploading, metadatasWaitCreateFolder.count) } } } + /// ------------------------ RENAME + /// + if let metadatasWaitRename = self.database.getMetadatas(predicate: NSPredicate(format: "status == %d", global.metadataStatusWaitRename), sortedByKeyPath: "serverUrl", ascending: true), !metadatasWaitRename.isEmpty { + for metadata in metadatasWaitRename { + let serverUrlFileNameSource = metadata.serveUrlFileName + let serverUrlFileNameDestination = metadata.serverUrl + "/" + metadata.fileName + let result = await NCNetworking.shared.moveFileOrFolder(serverUrlFileNameSource: serverUrlFileNameSource, serverUrlFileNameDestination: serverUrlFileNameDestination, overwrite: false, account: metadata.account) + if result.error == .success { + database.renameMetadata(ocId: metadata.ocId) + } else { + database.restoreMetadataServerUrlFileName(ocId: metadata.ocId) + } + } + return (counterDownloading, counterUploading, metadatasWaitRename.count) + } + /// ------------------------ DOWNLOAD /// let limitDownload = maxConcurrentOperationDownload - counterDownloading @@ -195,13 +211,13 @@ class NCNetworkingProcess { /// E2EE - only one for time for metadata in metadatasUploading.unique(map: { $0.serverUrl }) { if metadata.isDirectoryE2EE { - return (counterDownloading, counterUploading) + return (counterDownloading, counterUploading, 0) } } /// CHUNK - only one for time if !metadatasUploading.filter({ $0.chunk > 0 }).isEmpty { - return (counterDownloading, counterUploading) + return (counterDownloading, counterUploading, 0) } for sessionSelector in sessionUploadSelectors where counterUploading < maxConcurrentOperationUpload { @@ -287,7 +303,7 @@ class NCNetworkingProcess { } } - return (counterDownloading, counterUploading) + return (counterDownloading, counterUploading, 0) } private func checkApplicationState() async -> UIApplication.State { @@ -301,7 +317,7 @@ class NCNetworkingProcess { // MARK: - Public - func refreshProcessingTask() async -> (counterDownloading: Int, counterUploading: Int) { + func refreshProcessingTask() async -> (counterDownloading: Int, counterUploading: Int, counterWebDAV: Int) { await withCheckedContinuation { continuation in self.lockQueue.sync { guard !self.hasRun, NCNetworking.shared.isOnline else { return } From 0aaf6a706fdf9e3c716ba9674370b25e583f1dd1 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Wed, 2 Oct 2024 15:59:49 +0200 Subject: [PATCH 09/23] cod Signed-off-by: Marino Faggiana --- .../FileProviderExtension+Actions.swift | 2 +- .../Data/NCManageDatabase+Metadata.swift | 18 +++++++------- .../UIAlertController+Extension.swift | 24 ++++++++----------- .../Networking/NCNetworking+WebDAV.swift | 3 +++ .../Networking/NCNetworkingProcess.swift | 2 +- 5 files changed, 23 insertions(+), 26 deletions(-) diff --git a/File Provider Extension/FileProviderExtension+Actions.swift b/File Provider Extension/FileProviderExtension+Actions.swift index 4cea0984e4..ac853c1f0b 100644 --- a/File Provider Extension/FileProviderExtension+Actions.swift +++ b/File Provider Extension/FileProviderExtension+Actions.swift @@ -147,7 +147,7 @@ extension FileProviderExtension { NextcloudKit.shared.moveFileOrFolder(serverUrlFileNameSource: fileNamePathFrom, serverUrlFileNameDestination: fileNamePathTo, overwrite: false, account: metadata.account) { account, error in if error == .success { // Rename metadata - self.database.renameMetadata(fileNameTo: itemName, ocId: ocId, account: account) + self.database.renameMetadata(fileNameNew: itemName, ocId: ocId, account: account, withServeUrlFileName: true) guard let metadata = self.database.getMetadataFromOcId(ocId) else { return completionHandler(nil, NSFileProviderError(.noSuchItem)) diff --git a/iOSClient/Data/NCManageDatabase+Metadata.swift b/iOSClient/Data/NCManageDatabase+Metadata.swift index ab76ed45c9..42174178e1 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata.swift @@ -617,17 +617,20 @@ extension NCManageDatabase { } } - func renameMetadata(fileNameTo: String, ocId: String, account: String) { + func renameMetadata(fileNameNew: String, ocId: String, account: String, withServeUrlFileName: Bool = false) { do { let realm = try Realm() try realm.write { if let result = realm.objects(tableMetadata.self).filter("ocId == %@", ocId).first { - let resultsType = NextcloudKit.shared.nkCommonInstance.getInternalType(fileName: fileNameTo, mimeType: "", directory: result.directory, account: account) - result.fileName = fileNameTo - result.fileNameView = fileNameTo + let resultsType = NextcloudKit.shared.nkCommonInstance.getInternalType(fileName: fileNameNew, mimeType: "", directory: result.directory, account: account) + result.fileName = fileNameNew + result.fileNameView = fileNameNew result.iconName = resultsType.iconName result.contentType = resultsType.mimeType result.classFile = resultsType.classFile + if withServeUrlFileName { + result.serveUrlFileName = self.utilityFileSystem.stringAppendServerUrl(result.serverUrl, addFileName: fileNameNew) + } } } } catch let error { @@ -635,16 +638,11 @@ extension NCManageDatabase { } } - func renameMetadata(ocId: String) { + func setMetadataServeUrlFileName(ocId: String) { do { let realm = try Realm() try realm.write { if let result = realm.objects(tableMetadata.self).filter("ocId == %@", ocId).first { - let resultsType = NextcloudKit.shared.nkCommonInstance.getInternalType(fileName: result.fileName, mimeType: "", directory: result.directory, account: result.account) - - result.iconName = resultsType.iconName - result.contentType = resultsType.mimeType - result.classFile = resultsType.classFile result.serveUrlFileName = self.utilityFileSystem.stringAppendServerUrl(result.serverUrl, addFileName: result.fileName) } } diff --git a/iOSClient/Extensions/UIAlertController+Extension.swift b/iOSClient/Extensions/UIAlertController+Extension.swift index 7cd7f2de67..92e2a73cb4 100644 --- a/iOSClient/Extensions/UIAlertController+Extension.swift +++ b/iOSClient/Extensions/UIAlertController+Extension.swift @@ -202,28 +202,24 @@ extension UIAlertController { let alertController = UIAlertController(title: NSLocalizedString("_rename_", comment: ""), message: nil, preferredStyle: .alert) let okAction = UIAlertAction(title: NSLocalizedString("_save_", comment: ""), style: .default, handler: { _ in - guard let newFileName = alertController.textFields?.first?.text else { return } + guard let fileNameNew = alertController.textFields?.first?.text else { return } // verify if already exists - if NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileName == %@", metadata.account, metadata.serverUrl, newFileName)) != nil { + if NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileName == %@", metadata.account, metadata.serverUrl, fileNameNew)) != nil { NCContentPresenter().showError(error: NKError(errorCode: 0, errorDescription: "_rename_already_exists_")) return } - NCActivityIndicator.shared.start() - - - - /* - NCNetworking.shared.renameMetadata(metadata, fileNameNew: newFileName) { error in - - NCActivityIndicator.shared.stop() - - if error != .success { - NCContentPresenter().showError(error: error) + if metadata.isDirectoryE2EE, NCNetworking.shared.isOnline { + Task { + let error = await NCNetworkingE2EERename().rename(metadata: metadata, fileNameNew: fileNameNew) + if error != .success { + NCContentPresenter().showError(error: error) + } } + } else { + NCNetworking.shared.renameMetadata(metadata, fileNameNew: fileNameNew) } - */ }) // text field is initially empty, no action diff --git a/iOSClient/Networking/NCNetworking+WebDAV.swift b/iOSClient/Networking/NCNetworking+WebDAV.swift index e9e00c9f79..b6104c2798 100644 --- a/iOSClient/Networking/NCNetworking+WebDAV.swift +++ b/iOSClient/Networking/NCNetworking+WebDAV.swift @@ -384,6 +384,7 @@ extension NCNetworking { // MARK: - Rename + /* func renameMetadata(_ metadata: tableMetadata, fileNameNew: String, completion: @escaping (_ error: NKError) -> Void) { @@ -429,6 +430,7 @@ extension NCNetworking { } } + private func renameMetadataPlain(_ metadata: tableMetadata, fileNameNew: String, completion: @escaping (_ error: NKError) -> Void) { @@ -478,6 +480,7 @@ extension NCNetworking { completion(error) } } + */ func renameMetadata(_ metadata: tableMetadata, fileNameNew: String) { let permission = utility.permissionsContainsString(metadata.permissions, permissions: NCPermissions().permissionCanRename) diff --git a/iOSClient/Networking/NCNetworkingProcess.swift b/iOSClient/Networking/NCNetworkingProcess.swift index ce098c7a6d..d0af8577c2 100644 --- a/iOSClient/Networking/NCNetworkingProcess.swift +++ b/iOSClient/Networking/NCNetworkingProcess.swift @@ -175,7 +175,7 @@ class NCNetworkingProcess { let serverUrlFileNameDestination = metadata.serverUrl + "/" + metadata.fileName let result = await NCNetworking.shared.moveFileOrFolder(serverUrlFileNameSource: serverUrlFileNameSource, serverUrlFileNameDestination: serverUrlFileNameDestination, overwrite: false, account: metadata.account) if result.error == .success { - database.renameMetadata(ocId: metadata.ocId) + database.setMetadataServeUrlFileName(ocId: metadata.ocId) } else { database.restoreMetadataServerUrlFileName(ocId: metadata.ocId) } From fbd7e917992c3c7233f2cbf8f3e183c2c2a8f9ca Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Wed, 2 Oct 2024 16:26:27 +0200 Subject: [PATCH 10/23] cod Signed-off-by: Marino Faggiana --- .../FileProviderExtension+Actions.swift | 3 ++- iOSClient/Data/NCManageDatabase+Metadata.swift | 9 ++++----- .../Collection Common/NCCollectionViewCommon.swift | 9 ++++++++- iOSClient/NCGlobal.swift | 2 +- .../Networking/E2EE/NCNetworkingE2EERename.swift | 2 +- iOSClient/Networking/NCNetworking+WebDAV.swift | 12 +----------- iOSClient/Networking/NCNetworkingProcess.swift | 5 +++-- .../Supporting Files/en.lproj/Localizable.strings | 3 ++- 8 files changed, 22 insertions(+), 23 deletions(-) diff --git a/File Provider Extension/FileProviderExtension+Actions.swift b/File Provider Extension/FileProviderExtension+Actions.swift index ac853c1f0b..60a468e1ba 100644 --- a/File Provider Extension/FileProviderExtension+Actions.swift +++ b/File Provider Extension/FileProviderExtension+Actions.swift @@ -147,7 +147,8 @@ extension FileProviderExtension { NextcloudKit.shared.moveFileOrFolder(serverUrlFileNameSource: fileNamePathFrom, serverUrlFileNameDestination: fileNamePathTo, overwrite: false, account: metadata.account) { account, error in if error == .success { // Rename metadata - self.database.renameMetadata(fileNameNew: itemName, ocId: ocId, account: account, withServeUrlFileName: true) + self.database.renameMetadata(fileNameNew: itemName, ocId: ocId, account: account) + self.database.setMetadataServeUrlFileNameStatusNormal(ocId: ocId) guard let metadata = self.database.getMetadataFromOcId(ocId) else { return completionHandler(nil, NSFileProviderError(.noSuchItem)) diff --git a/iOSClient/Data/NCManageDatabase+Metadata.swift b/iOSClient/Data/NCManageDatabase+Metadata.swift index 42174178e1..7c7890332a 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata.swift @@ -617,7 +617,7 @@ extension NCManageDatabase { } } - func renameMetadata(fileNameNew: String, ocId: String, account: String, withServeUrlFileName: Bool = false) { + func renameMetadata(fileNameNew: String, ocId: String, account: String, status: Int = NCGlobal.shared.metadataStatusNormal) { do { let realm = try Realm() try realm.write { @@ -628,9 +628,7 @@ extension NCManageDatabase { result.iconName = resultsType.iconName result.contentType = resultsType.mimeType result.classFile = resultsType.classFile - if withServeUrlFileName { - result.serveUrlFileName = self.utilityFileSystem.stringAppendServerUrl(result.serverUrl, addFileName: fileNameNew) - } + result.status = status } } } catch let error { @@ -638,12 +636,13 @@ extension NCManageDatabase { } } - func setMetadataServeUrlFileName(ocId: String) { + func setMetadataServeUrlFileNameStatusNormal(ocId: String) { do { let realm = try Realm() try realm.write { if let result = realm.objects(tableMetadata.self).filter("ocId == %@", ocId).first { result.serveUrlFileName = self.utilityFileSystem.stringAppendServerUrl(result.serverUrl, addFileName: result.fileName) + result.status = NCGlobal.shared.metadataStatusNormal } } } catch let error { diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift index 1b600a0a45..0f39268e5e 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon.swift @@ -415,9 +415,16 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS @objc func renameFile(_ notification: NSNotification) { guard let userInfo = notification.userInfo as NSDictionary?, let account = userInfo["account"] as? String, - account == session.account + let serverUrl = userInfo["serverUrl"] as? String, + let error = userInfo["error"] as? NKError, + account == session.account, + serverUrl == self.serverUrl else { return } + if error != .success { + NCContentPresenter().showError(error: error) + } + reloadDataSource() } diff --git a/iOSClient/NCGlobal.swift b/iOSClient/NCGlobal.swift index 13ce261eda..8914a82851 100644 --- a/iOSClient/NCGlobal.swift +++ b/iOSClient/NCGlobal.swift @@ -316,7 +316,7 @@ class NCGlobal: NSObject { let notificationCenterDeleteFile = "deleteFile" // userInfo: [ocId], error let notificationCenterMoveFile = "moveFile" // userInfo: [ocId], error, dragdrop let notificationCenterCopyFile = "copyFile" // userInfo: [ocId], error, dragdrop - let notificationCenterRenameFile = "renameFile" // userInfo: ocId, account + let notificationCenterRenameFile = "renameFile" // userInfo: serverUrl, account, error let notificationCenterFavoriteFile = "favoriteFile" // userInfo: ocId, serverUrl let notificationCenterFileExists = "fileExists" // userInfo: ocId, fileExists diff --git a/iOSClient/Networking/E2EE/NCNetworkingE2EERename.swift b/iOSClient/Networking/E2EE/NCNetworkingE2EERename.swift index 48906ebe06..98aea3d44c 100644 --- a/iOSClient/Networking/E2EE/NCNetworkingE2EERename.swift +++ b/iOSClient/Networking/E2EE/NCNetworkingE2EERename.swift @@ -91,7 +91,7 @@ class NCNetworkingE2EERename: NSObject { // await networkingE2EE.unlock(account: metadata.account, serverUrl: metadata.serverUrl) - NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterRenameFile, userInfo: ["ocId": metadata.ocId, "account": metadata.account]) + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterRenameFile, userInfo: ["serverUrl": metadata.serverUrl, "account": metadata.account, "error": uploadMetadataError]) return NKError() } diff --git a/iOSClient/Networking/NCNetworking+WebDAV.swift b/iOSClient/Networking/NCNetworking+WebDAV.swift index b6104c2798..7480932059 100644 --- a/iOSClient/Networking/NCNetworking+WebDAV.swift +++ b/iOSClient/Networking/NCNetworking+WebDAV.swift @@ -489,17 +489,7 @@ extension NCNetworking { return } - /* - if metadata.status == global.metadataStatusWaitCreateFolder { - let metadatas = database.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl BEGINSWITH %@", metadata.account, metadata.serverUrl)) - for metadata in metadatas { - database.deleteMetadataOcId(metadata.ocId) - utilityFileSystem.removeFile(atPath: utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId)) - } - return - } - */ - self.database.setMetadataStatus(ocId: metadata.ocId, status: NCGlobal.shared.metadataStatusWaitDelete) + self.database.renameMetadata(fileNameNew: fileNameNew, ocId: metadata.ocId, account: metadata.account, status: NCGlobal.shared.metadataStatusWaitRename) } // MARK: - Move diff --git a/iOSClient/Networking/NCNetworkingProcess.swift b/iOSClient/Networking/NCNetworkingProcess.swift index d0af8577c2..0e89748002 100644 --- a/iOSClient/Networking/NCNetworkingProcess.swift +++ b/iOSClient/Networking/NCNetworkingProcess.swift @@ -159,7 +159,7 @@ class NCNetworkingProcess { if error != .success { if metadata.sessionError.isEmpty { let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileName - let message = String(format: NSLocalizedString("_offlinefolder_error_", comment: ""), serverUrlFileName) + let message = String(format: NSLocalizedString("_create_folder_error_", comment: ""), serverUrlFileName) NCContentPresenter().messageNotification(message, error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max) } return (counterDownloading, counterUploading, metadatasWaitCreateFolder.count) @@ -175,10 +175,11 @@ class NCNetworkingProcess { let serverUrlFileNameDestination = metadata.serverUrl + "/" + metadata.fileName let result = await NCNetworking.shared.moveFileOrFolder(serverUrlFileNameSource: serverUrlFileNameSource, serverUrlFileNameDestination: serverUrlFileNameDestination, overwrite: false, account: metadata.account) if result.error == .success { - database.setMetadataServeUrlFileName(ocId: metadata.ocId) + database.setMetadataServeUrlFileNameStatusNormal(ocId: metadata.ocId) } else { database.restoreMetadataServerUrlFileName(ocId: metadata.ocId) } + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterRenameFile, userInfo: ["serverUrl": metadata.serverUrl, "account": metadata.account, "error": result.error]) } return (counterDownloading, counterUploading, metadatasWaitRename.count) } diff --git a/iOSClient/Supporting Files/en.lproj/Localizable.strings b/iOSClient/Supporting Files/en.lproj/Localizable.strings index 0e1fbf5220..0b3b0e1f85 100644 --- a/iOSClient/Supporting Files/en.lproj/Localizable.strings +++ b/iOSClient/Supporting Files/en.lproj/Localizable.strings @@ -1026,7 +1026,8 @@ "_maintenance_mode_" = "Server is currently in maintenance mode"; "_upload_foreground_msg_" = "Do not close %@ to complete the transfer …"; "_upload_background_msg_" = "Files upload in progress …"; -"_offlinefolder_error_" = "An error has occurred while creating the folder:\n%@.\n\nPlease resolve the issue as soon as possible.\n\nAll uploads are suspended until the problem is resolved.\n"; +"_create_folder_error_" = "An error has occurred while creating the folder:\n%@.\n\nPlease resolve the issue as soon as possible.\n\nAll uploads are suspended until the problem is resolved.\n"; +"_rename_file_error_" = "An error has occurred while renaming the file:\n%@."; "_creating_dir_progress_" = "Creating directories in progress … keep the application active"; "_creating_db_photo_progress" = "Creating photo archive in progress … keep the application active"; "_account_unauthorized_" = "Warning, %@, you are not authorized, your account has been deleted, if you have changed your password, re-authenticate."; From 1ff0d851ec39b1d83f7dc4fd6750c974ce020fde Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Wed, 2 Oct 2024 17:01:40 +0200 Subject: [PATCH 11/23] cod Signed-off-by: Marino Faggiana --- iOSClient/Data/NCManageDatabase+Metadata+Session.swift | 7 ++----- iOSClient/Extensions/UIAlertController+Extension.swift | 2 ++ iOSClient/Networking/NCNetworking+Task.swift | 4 ++-- iOSClient/Networking/NCNetworkingProcess.swift | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/iOSClient/Data/NCManageDatabase+Metadata+Session.swift b/iOSClient/Data/NCManageDatabase+Metadata+Session.swift index c15fcbb356..b4c27bf819 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata+Session.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata+Session.swift @@ -190,7 +190,7 @@ extension NCManageDatabase { sessionTaskIdentifier)) } - func restoreMetadataServerUrlFileName(ocId: String) { + func restoreMetadataFileName(ocId: String) { do { let realm = try Realm() try realm.write { @@ -201,11 +201,8 @@ extension NCManageDatabase { let lastPathComponent = url.lastPathComponent let fileName = lastPathComponent.removingPercentEncoding ?? lastPathComponent - let baseURL = url.deletingLastPathComponent().absoluteString - let serverUrl = baseURL.removingPercentEncoding ?? baseURL - - result.serverUrl = serverUrl result.fileName = fileName + result.fileNameView = fileName result.status = NCGlobal.shared.metadataStatusNormal } } diff --git a/iOSClient/Extensions/UIAlertController+Extension.swift b/iOSClient/Extensions/UIAlertController+Extension.swift index 92e2a73cb4..dcfec1cbba 100644 --- a/iOSClient/Extensions/UIAlertController+Extension.swift +++ b/iOSClient/Extensions/UIAlertController+Extension.swift @@ -220,6 +220,8 @@ extension UIAlertController { } else { NCNetworking.shared.renameMetadata(metadata, fileNameNew: fileNameNew) } + + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSource, userInfo: ["serverUrl": metadata.serverUrl]) }) // text field is initially empty, no action diff --git a/iOSClient/Networking/NCNetworking+Task.swift b/iOSClient/Networking/NCNetworking+Task.swift index deb1ac7a09..c33ad75e76 100644 --- a/iOSClient/Networking/NCNetworking+Task.swift +++ b/iOSClient/Networking/NCNetworking+Task.swift @@ -65,7 +65,7 @@ extension NCNetworking { /// RENAME /// if metadata.status == global.metadataStatusWaitRename { - database.restoreMetadataServerUrlFileName(ocId: metadata.ocId) + database.restoreMetadataFileName(ocId: metadata.ocId) NotificationCenter.default.postOnMainThread(name: self.global.notificationCenterReloadDataSource) return } @@ -144,7 +144,7 @@ extension NCNetworking { utilityFileSystem.removeFile(atPath: utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId)) } } else if metadata.status == global.metadataStatusWaitRename { - database.restoreMetadataServerUrlFileName(ocId: metadata.ocId) + database.restoreMetadataFileName(ocId: metadata.ocId) } } NotificationCenter.default.postOnMainThread(name: self.global.notificationCenterReloadDataSource) diff --git a/iOSClient/Networking/NCNetworkingProcess.swift b/iOSClient/Networking/NCNetworkingProcess.swift index 0e89748002..5f00bf183a 100644 --- a/iOSClient/Networking/NCNetworkingProcess.swift +++ b/iOSClient/Networking/NCNetworkingProcess.swift @@ -177,7 +177,7 @@ class NCNetworkingProcess { if result.error == .success { database.setMetadataServeUrlFileNameStatusNormal(ocId: metadata.ocId) } else { - database.restoreMetadataServerUrlFileName(ocId: metadata.ocId) + database.restoreMetadataFileName(ocId: metadata.ocId) } NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterRenameFile, userInfo: ["serverUrl": metadata.serverUrl, "account": metadata.account, "error": result.error]) } From 7bdd7ff910f75e5903afa8443ddc17030c81cddb Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Wed, 2 Oct 2024 17:24:49 +0200 Subject: [PATCH 12/23] cod Signed-off-by: Marino Faggiana --- .../NCManageDatabase+Metadata+Session.swift | 21 ---- .../Data/NCManageDatabase+Metadata.swift | 30 ++++++ .../Networking/NCNetworking+WebDAV.swift | 98 ------------------- 3 files changed, 30 insertions(+), 119 deletions(-) diff --git a/iOSClient/Data/NCManageDatabase+Metadata+Session.swift b/iOSClient/Data/NCManageDatabase+Metadata+Session.swift index b4c27bf819..1242b6616a 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata+Session.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata+Session.swift @@ -189,25 +189,4 @@ extension NCManageDatabase { fileName, sessionTaskIdentifier)) } - - func restoreMetadataFileName(ocId: String) { - do { - let realm = try Realm() - try realm.write { - if let result = realm.objects(tableMetadata.self).filter("ocId == %@", ocId).first, - let encodedURLString = result.serveUrlFileName.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), - let url = URL(string: encodedURLString) { - - let lastPathComponent = url.lastPathComponent - let fileName = lastPathComponent.removingPercentEncoding ?? lastPathComponent - - result.fileName = fileName - result.fileNameView = fileName - result.status = NCGlobal.shared.metadataStatusNormal - } - } - } catch let error { - NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Could not write to database: \(error)") - } - } } diff --git a/iOSClient/Data/NCManageDatabase+Metadata.swift b/iOSClient/Data/NCManageDatabase+Metadata.swift index 7c7890332a..afe48a0f00 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata.swift @@ -623,12 +623,42 @@ extension NCManageDatabase { try realm.write { if let result = realm.objects(tableMetadata.self).filter("ocId == %@", ocId).first { let resultsType = NextcloudKit.shared.nkCommonInstance.getInternalType(fileName: fileNameNew, mimeType: "", directory: result.directory, account: account) + let atPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(result.ocId) + "/" + result.fileNameView + let toPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(result.ocId) + "/" + fileNameNew + result.fileName = fileNameNew result.fileNameView = fileNameNew result.iconName = resultsType.iconName result.contentType = resultsType.mimeType result.classFile = resultsType.classFile result.status = status + + self.utilityFileSystem.moveFile(atPath: atPath, toPath: toPath) + } + } + } catch let error { + NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Could not write to database: \(error)") + } + } + + func restoreMetadataFileName(ocId: String) { + do { + let realm = try Realm() + try realm.write { + if let result = realm.objects(tableMetadata.self).filter("ocId == %@", ocId).first, + let encodedURLString = result.serveUrlFileName.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), + let url = URL(string: encodedURLString) { + let lastPathComponent = url.lastPathComponent + let fileName = lastPathComponent.removingPercentEncoding ?? lastPathComponent + + let atPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(result.ocId) + "/" + result.fileNameView + let toPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(result.ocId) + "/" + fileName + + result.fileName = fileName + result.fileNameView = fileName + result.status = NCGlobal.shared.metadataStatusNormal + + self.utilityFileSystem.moveFile(atPath: atPath, toPath: toPath) } } } catch let error { diff --git a/iOSClient/Networking/NCNetworking+WebDAV.swift b/iOSClient/Networking/NCNetworking+WebDAV.swift index 7480932059..9c5796e4cc 100644 --- a/iOSClient/Networking/NCNetworking+WebDAV.swift +++ b/iOSClient/Networking/NCNetworking+WebDAV.swift @@ -384,104 +384,6 @@ extension NCNetworking { // MARK: - Rename - /* - func renameMetadata(_ metadata: tableMetadata, - fileNameNew: String, - completion: @escaping (_ error: NKError) -> Void) { - let metadataLive = self.database.getMetadataLivePhoto(metadata: metadata) - let fileNameNew = fileNameNew.trimmingCharacters(in: .whitespacesAndNewlines) - let fileNameNewLive = (fileNameNew as NSString).deletingPathExtension + ".mov" - - if metadata.status == NCGlobal.shared.metadataStatusWaitCreateFolder { - metadata.fileName = fileNameNew - metadata.fileNameView = fileNameNew - self.database.addMetadata(metadata) - NotificationCenter.default.postOnMainThread(name: self.global.notificationCenterRenameFile, userInfo: ["ocId": metadata.ocId, "account": metadata.account]) - completion(.success) - } else if metadata.isDirectoryE2EE { -#if !EXTENSION - Task { - if let metadataLive = metadataLive { - let error = await NCNetworkingE2EERename().rename(metadata: metadataLive, fileNameNew: fileNameNew) - if error == .success { - let error = await NCNetworkingE2EERename().rename(metadata: metadata, fileNameNew: fileNameNew) - DispatchQueue.main.async { completion(error) } - } else { - DispatchQueue.main.async { completion(error) } - } - } else { - let error = await NCNetworkingE2EERename().rename(metadata: metadata, fileNameNew: fileNameNew) - DispatchQueue.main.async { completion(error) } - } - } -#endif - } else { - if let metadataLive, metadata.isNotFlaggedAsLivePhotoByServer { - renameMetadataPlain(metadataLive, fileNameNew: fileNameNewLive) { error in - if error == .success { - self.renameMetadataPlain(metadata, fileNameNew: fileNameNew, completion: completion) - } else { - completion(error) - } - } - } else { - renameMetadataPlain(metadata, fileNameNew: fileNameNew, completion: completion) - } - } - } - - - private func renameMetadataPlain(_ metadata: tableMetadata, - fileNameNew: String, - completion: @escaping (_ error: NKError) -> Void) { - let permission = utility.permissionsContainsString(metadata.permissions, permissions: NCPermissions().permissionCanRename) - if !metadata.permissions.isEmpty && !permission { - return completion(NKError(errorCode: self.global.errorInternalError, errorDescription: "_no_permission_modify_file_")) - } - let fileName = utility.removeForbiddenCharacters(fileNameNew) - if fileName != fileNameNew { - let errorDescription = String(format: NSLocalizedString("_forbidden_characters_", comment: ""), self.global.forbiddenCharacters.joined(separator: " ")) - let error = NKError(errorCode: self.global.errorConflict, errorDescription: errorDescription) - return completion(error) - } - let fileNameNew = fileName - if fileNameNew.isEmpty || fileNameNew == metadata.fileNameView { - return completion(NKError()) - } - let fileNamePath = metadata.serverUrl + "/" + metadata.fileName - let fileNameToPath = metadata.serverUrl + "/" + fileNameNew - - NextcloudKit.shared.moveFileOrFolder(serverUrlFileNameSource: fileNamePath, serverUrlFileNameDestination: fileNameToPath, overwrite: false, account: metadata.account) { account, error in - if error == .success { - self.database.renameMetadata(fileNameTo: fileNameNew, ocId: metadata.ocId, account: account) - if metadata.directory { - let serverUrl = self.utilityFileSystem.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName) - let serverUrlTo = self.utilityFileSystem.stringAppendServerUrl(metadata.serverUrl, addFileName: fileNameNew) - if let directory = self.database.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", metadata.account, metadata.serverUrl)) { - self.database.setDirectory(serverUrl: serverUrl, - serverUrlTo: serverUrlTo, - etag: "", - encrypted: directory.e2eEncrypted, - account: metadata.account) - } - } else { - if (metadata.fileName as NSString).pathExtension != (fileNameNew as NSString).pathExtension { - let path = self.utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId) - self.utilityFileSystem.removeFile(atPath: path) - } else { - self.database.setLocalFile(ocId: metadata.ocId, fileName: fileNameNew) - let atPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId) + "/" + metadata.fileName - let toPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId) + "/" + fileNameNew - self.utilityFileSystem.moveFile(atPath: atPath, toPath: toPath) - } - } - NotificationCenter.default.postOnMainThread(name: self.global.notificationCenterRenameFile, userInfo: ["ocId": metadata.ocId, "account": metadata.account]) - } - completion(error) - } - } - */ - func renameMetadata(_ metadata: tableMetadata, fileNameNew: String) { let permission = utility.permissionsContainsString(metadata.permissions, permissions: NCPermissions().permissionCanRename) if !metadata.permissions.isEmpty && permission == false { From 080982f58f76e49e3ba9f225fdd69b5a43de19fd Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Wed, 2 Oct 2024 17:30:04 +0200 Subject: [PATCH 13/23] cod Signed-off-by: Marino Faggiana --- .../Data/NCManageDatabase+Metadata.swift | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/iOSClient/Data/NCManageDatabase+Metadata.swift b/iOSClient/Data/NCManageDatabase+Metadata.swift index afe48a0f00..5435cab44e 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata.swift @@ -622,9 +622,8 @@ extension NCManageDatabase { let realm = try Realm() try realm.write { if let result = realm.objects(tableMetadata.self).filter("ocId == %@", ocId).first { + let fileNameView = result.fileNameView let resultsType = NextcloudKit.shared.nkCommonInstance.getInternalType(fileName: fileNameNew, mimeType: "", directory: result.directory, account: account) - let atPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(result.ocId) + "/" + result.fileNameView - let toPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(result.ocId) + "/" + fileNameNew result.fileName = fileNameNew result.fileNameView = fileNameNew @@ -633,7 +632,12 @@ extension NCManageDatabase { result.classFile = resultsType.classFile result.status = status - self.utilityFileSystem.moveFile(atPath: atPath, toPath: toPath) + if !result.directory { + let atPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(result.ocId) + "/" + fileNameView + let toPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(result.ocId) + "/" + fileNameNew + + self.utilityFileSystem.moveFile(atPath: atPath, toPath: toPath) + } } } } catch let error { @@ -650,15 +654,18 @@ extension NCManageDatabase { let url = URL(string: encodedURLString) { let lastPathComponent = url.lastPathComponent let fileName = lastPathComponent.removingPercentEncoding ?? lastPathComponent - - let atPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(result.ocId) + "/" + result.fileNameView - let toPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(result.ocId) + "/" + fileName + let fileNameView = result.fileNameView result.fileName = fileName result.fileNameView = fileName result.status = NCGlobal.shared.metadataStatusNormal - self.utilityFileSystem.moveFile(atPath: atPath, toPath: toPath) + if !result.directory { + let atPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(result.ocId) + "/" + fileNameView + let toPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(result.ocId) + "/" + fileName + + self.utilityFileSystem.moveFile(atPath: atPath, toPath: toPath) + } } } } catch let error { From 3404f531e1a0a89ffed61d7ca8a8de55855b74db Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Wed, 2 Oct 2024 18:00:43 +0200 Subject: [PATCH 14/23] live Signed-off-by: Marino Faggiana --- .../Data/NCManageDatabase+Metadata.swift | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/iOSClient/Data/NCManageDatabase+Metadata.swift b/iOSClient/Data/NCManageDatabase+Metadata.swift index 5435cab44e..2aef0e92cc 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata.swift @@ -623,6 +623,7 @@ extension NCManageDatabase { try realm.write { if let result = realm.objects(tableMetadata.self).filter("ocId == %@", ocId).first { let fileNameView = result.fileNameView + let fileIdMOV = result.livePhotoFile let resultsType = NextcloudKit.shared.nkCommonInstance.getInternalType(fileName: fileNameNew, mimeType: "", directory: result.directory, account: account) result.fileName = fileNameNew @@ -638,6 +639,20 @@ extension NCManageDatabase { self.utilityFileSystem.moveFile(atPath: atPath, toPath: toPath) } + + if result.isLivePhoto, + let resultMOV = realm.objects(tableMetadata.self).filter("fileId == %@ AND account == %@", fileIdMOV, result.account).first { + let fileNameView = resultMOV.fileNameView + let fileName = (fileNameNew as NSString).deletingPathExtension + let ext = (resultMOV.fileName as NSString).pathExtension + resultMOV.fileName = fileName + "." + ext + resultMOV.fileNameView = fileName + "." + ext + + let atPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(resultMOV.ocId) + "/" + fileNameView + let toPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(resultMOV.ocId) + "/" + fileName + "." + ext + + self.utilityFileSystem.moveFile(atPath: atPath, toPath: toPath) + } } } } catch let error { @@ -652,6 +667,7 @@ extension NCManageDatabase { if let result = realm.objects(tableMetadata.self).filter("ocId == %@", ocId).first, let encodedURLString = result.serveUrlFileName.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), let url = URL(string: encodedURLString) { + let fileIdMOV = result.livePhotoFile let lastPathComponent = url.lastPathComponent let fileName = lastPathComponent.removingPercentEncoding ?? lastPathComponent let fileNameView = result.fileNameView @@ -666,6 +682,20 @@ extension NCManageDatabase { self.utilityFileSystem.moveFile(atPath: atPath, toPath: toPath) } + + if result.isLivePhoto, + let resultMOV = realm.objects(tableMetadata.self).filter("fileId == %@ AND account == %@", fileIdMOV, result.account).first { + let fileNameView = resultMOV.fileNameView + let fileName = (fileName as NSString).deletingPathExtension + let ext = (resultMOV.fileName as NSString).pathExtension + resultMOV.fileName = fileName + "." + ext + resultMOV.fileNameView = fileName + "." + ext + + let atPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(resultMOV.ocId) + "/" + fileNameView + let toPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(resultMOV.ocId) + "/" + fileName + "." + ext + + self.utilityFileSystem.moveFile(atPath: atPath, toPath: toPath) + } } } } catch let error { From a81d9a9b8b1897e3df88ef0df63ff67076d2d2c8 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Wed, 2 Oct 2024 18:23:28 +0200 Subject: [PATCH 15/23] dir Signed-off-by: Marino Faggiana --- .../FileProviderExtension+Actions.swift | 2 +- .../Data/NCManageDatabase+Metadata.swift | 20 +++++++++++++++---- .../Networking/NCNetworking+WebDAV.swift | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/File Provider Extension/FileProviderExtension+Actions.swift b/File Provider Extension/FileProviderExtension+Actions.swift index 60a468e1ba..322fb9ff9e 100644 --- a/File Provider Extension/FileProviderExtension+Actions.swift +++ b/File Provider Extension/FileProviderExtension+Actions.swift @@ -147,7 +147,7 @@ extension FileProviderExtension { NextcloudKit.shared.moveFileOrFolder(serverUrlFileNameSource: fileNamePathFrom, serverUrlFileNameDestination: fileNamePathTo, overwrite: false, account: metadata.account) { account, error in if error == .success { // Rename metadata - self.database.renameMetadata(fileNameNew: itemName, ocId: ocId, account: account) + self.database.renameMetadata(fileNameNew: itemName, ocId: ocId) self.database.setMetadataServeUrlFileNameStatusNormal(ocId: ocId) guard let metadata = self.database.getMetadataFromOcId(ocId) else { diff --git a/iOSClient/Data/NCManageDatabase+Metadata.swift b/iOSClient/Data/NCManageDatabase+Metadata.swift index 2aef0e92cc..2fc1ae1db9 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata.swift @@ -617,14 +617,15 @@ extension NCManageDatabase { } } - func renameMetadata(fileNameNew: String, ocId: String, account: String, status: Int = NCGlobal.shared.metadataStatusNormal) { + func renameMetadata(fileNameNew: String, ocId: String, status: Int = NCGlobal.shared.metadataStatusNormal) { do { let realm = try Realm() try realm.write { if let result = realm.objects(tableMetadata.self).filter("ocId == %@", ocId).first { let fileNameView = result.fileNameView let fileIdMOV = result.livePhotoFile - let resultsType = NextcloudKit.shared.nkCommonInstance.getInternalType(fileName: fileNameNew, mimeType: "", directory: result.directory, account: account) + let directoryServerUrl = self.utilityFileSystem.stringAppendServerUrl(result.serverUrl, addFileName: fileNameView) + let resultsType = NextcloudKit.shared.nkCommonInstance.getInternalType(fileName: fileNameNew, mimeType: "", directory: result.directory, account: result.account) result.fileName = fileNameNew result.fileNameView = fileNameNew @@ -633,7 +634,12 @@ extension NCManageDatabase { result.classFile = resultsType.classFile result.status = status - if !result.directory { + if result.directory, + let resultDirectory = realm.objects(tableDirectory.self).filter("account == %@ AND serverUrl == %@", result.account, directoryServerUrl).first { + let serverUrlTo = self.utilityFileSystem.stringAppendServerUrl(result.serverUrl, addFileName: fileNameNew) + + resultDirectory.serverUrl = serverUrlTo + } else { let atPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(result.ocId) + "/" + fileNameView let toPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(result.ocId) + "/" + fileNameNew @@ -668,6 +674,7 @@ extension NCManageDatabase { let encodedURLString = result.serveUrlFileName.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), let url = URL(string: encodedURLString) { let fileIdMOV = result.livePhotoFile + let directoryServerUrl = self.utilityFileSystem.stringAppendServerUrl(result.serverUrl, addFileName: result.fileNameView) let lastPathComponent = url.lastPathComponent let fileName = lastPathComponent.removingPercentEncoding ?? lastPathComponent let fileNameView = result.fileNameView @@ -676,7 +683,12 @@ extension NCManageDatabase { result.fileNameView = fileName result.status = NCGlobal.shared.metadataStatusNormal - if !result.directory { + if result.directory, + let resultDirectory = realm.objects(tableDirectory.self).filter("account == %@ AND serverUrl == %@", result.account, directoryServerUrl).first { + let serverUrlTo = self.utilityFileSystem.stringAppendServerUrl(result.serverUrl, addFileName: fileName) + + resultDirectory.serverUrl = serverUrlTo + } else { let atPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(result.ocId) + "/" + fileNameView let toPath = self.utilityFileSystem.getDirectoryProviderStorageOcId(result.ocId) + "/" + fileName diff --git a/iOSClient/Networking/NCNetworking+WebDAV.swift b/iOSClient/Networking/NCNetworking+WebDAV.swift index 9c5796e4cc..1b7bca7701 100644 --- a/iOSClient/Networking/NCNetworking+WebDAV.swift +++ b/iOSClient/Networking/NCNetworking+WebDAV.swift @@ -391,7 +391,7 @@ extension NCNetworking { return } - self.database.renameMetadata(fileNameNew: fileNameNew, ocId: metadata.ocId, account: metadata.account, status: NCGlobal.shared.metadataStatusWaitRename) + self.database.renameMetadata(fileNameNew: fileNameNew, ocId: metadata.ocId, status: NCGlobal.shared.metadataStatusWaitRename) } // MARK: - Move From 07bd9d3385d555e242fd98d2a19ac76250366a75 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Wed, 2 Oct 2024 18:42:30 +0200 Subject: [PATCH 16/23] cod Signed-off-by: Marino Faggiana --- iOSClient/Menu/NCCollectionViewCommon+Menu.swift | 3 +-- iOSClient/Networking/NCNetworkingProcess.swift | 2 +- iOSClient/Transfers/NCTransfers.swift | 12 ++++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/iOSClient/Menu/NCCollectionViewCommon+Menu.swift b/iOSClient/Menu/NCCollectionViewCommon+Menu.swift index 971dc5ec8d..6e912507c5 100644 --- a/iOSClient/Menu/NCCollectionViewCommon+Menu.swift +++ b/iOSClient/Menu/NCCollectionViewCommon+Menu.swift @@ -290,8 +290,7 @@ extension NCCollectionViewCommon { // // RENAME // - if NCNetworking.shared.isOnline, - metadata.isRenameable { + if metadata.isRenameable { actions.append( NCMenuAction( title: NSLocalizedString("_rename_", comment: ""), diff --git a/iOSClient/Networking/NCNetworkingProcess.swift b/iOSClient/Networking/NCNetworkingProcess.swift index 5f00bf183a..eb4817c360 100644 --- a/iOSClient/Networking/NCNetworkingProcess.swift +++ b/iOSClient/Networking/NCNetworkingProcess.swift @@ -151,7 +151,7 @@ class NCNetworkingProcess { return (counterDownloading, counterUploading, metadatasWaitDelete.count) } - /// ------------------------ FOLDER + /// ------------------------ CREATE FOLDER /// if let metadatasWaitCreateFolder = self.database.getMetadatas(predicate: NSPredicate(format: "status == %d", global.metadataStatusWaitCreateFolder), sortedByKeyPath: "serverUrl", ascending: true), !metadatasWaitCreateFolder.isEmpty { for metadata in metadatasWaitCreateFolder { diff --git a/iOSClient/Transfers/NCTransfers.swift b/iOSClient/Transfers/NCTransfers.swift index d88e239fae..cf24f8c582 100644 --- a/iOSClient/Transfers/NCTransfers.swift +++ b/iOSClient/Transfers/NCTransfers.swift @@ -63,6 +63,18 @@ class NCTransfers: NCCollectionViewCommon, NCTransferCellDelegate { // MARK: - NotificationCenter + override func deleteFile(_ notification: NSNotification) { + reloadDataSource() + } + + override func renameFile(_ notification: NSNotification) { + reloadDataSource() + } + + override func createFolder(_ notification: NSNotification) { + reloadDataSource() + } + override func downloadStartFile(_ notification: NSNotification) { reloadDataSource() } From 086268b8abd2de41404ac9b3c1777518e78d97c4 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Thu, 3 Oct 2024 10:13:06 +0200 Subject: [PATCH 17/23] e2ee Signed-off-by: Marino Faggiana --- iOSClient/Data/NCManageDatabase+Metadata.swift | 5 ++--- iOSClient/Files/NCFiles.swift | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/iOSClient/Data/NCManageDatabase+Metadata.swift b/iOSClient/Data/NCManageDatabase+Metadata.swift index 2fc1ae1db9..00ec3e3d4a 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata.swift @@ -555,18 +555,17 @@ extension NCManageDatabase { @discardableResult func addMetadata(_ metadata: tableMetadata) -> tableMetadata? { - let result = tableMetadata(value: metadata) do { let realm = try Realm() try realm.write { - realm.add(result, update: .all) + realm.add(metadata, update: .all) } } catch let error { NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Could not write to database: \(error)") return nil } - return result + return tableMetadata(value: metadata) } func addMetadatas(_ metadatas: [tableMetadata]) { diff --git a/iOSClient/Files/NCFiles.swift b/iOSClient/Files/NCFiles.swift index ded1f74c9d..1146eb3bef 100644 --- a/iOSClient/Files/NCFiles.swift +++ b/iOSClient/Files/NCFiles.swift @@ -175,6 +175,8 @@ class NCFiles: NCCollectionViewCommon { } else if self.dataSource.isEmpty() { self.collectionView.reloadData() } + } else if self.dataSource.isEmpty() { + self.collectionView.reloadData() } } } From 5794bcf8a3e3606faa1c4c0b2568ca71613dafea Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Thu, 3 Oct 2024 10:38:42 +0200 Subject: [PATCH 18/23] cod Signed-off-by: Marino Faggiana --- .../E2EE/NCNetworkingE2EEDelete.swift | 2 ++ .../Networking/NCNetworking+WebDAV.swift | 23 +++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/iOSClient/Networking/E2EE/NCNetworkingE2EEDelete.swift b/iOSClient/Networking/E2EE/NCNetworkingE2EEDelete.swift index 10917856aa..11b0261acb 100644 --- a/iOSClient/Networking/E2EE/NCNetworkingE2EEDelete.swift +++ b/iOSClient/Networking/E2EE/NCNetworkingE2EEDelete.swift @@ -105,6 +105,8 @@ class NCNetworkingE2EEDelete: NSObject { // await networkingE2EE.unlock(account: metadata.account, serverUrl: metadata.serverUrl) + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": [metadata.ocId], "error": NKError()]) + return NKError() } } diff --git a/iOSClient/Networking/NCNetworking+WebDAV.swift b/iOSClient/Networking/NCNetworking+WebDAV.swift index 1b7bca7701..d4086354e5 100644 --- a/iOSClient/Networking/NCNetworking+WebDAV.swift +++ b/iOSClient/Networking/NCNetworking+WebDAV.swift @@ -371,15 +371,24 @@ extension NCNetworking { return } - if metadata.status == global.metadataStatusWaitCreateFolder { - let metadatas = database.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl BEGINSWITH %@", metadata.account, metadata.serverUrl)) - for metadata in metadatas { - database.deleteMetadataOcId(metadata.ocId) - utilityFileSystem.removeFile(atPath: utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId)) + if metadata.isDirectoryE2EE, NCNetworking.shared.isOnline { + #if !EXTENSION + Task { + return await NCNetworkingE2EEDelete().delete(metadata: metadata) } - return + #endif + } else { + + if metadata.status == global.metadataStatusWaitCreateFolder { + let metadatas = database.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl BEGINSWITH %@", metadata.account, metadata.serverUrl)) + for metadata in metadatas { + database.deleteMetadataOcId(metadata.ocId) + utilityFileSystem.removeFile(atPath: utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId)) + } + return + } + self.database.setMetadataStatus(ocId: metadata.ocId, status: NCGlobal.shared.metadataStatusWaitDelete) } - self.database.setMetadataStatus(ocId: metadata.ocId, status: NCGlobal.shared.metadataStatusWaitDelete) } // MARK: - Rename From e91ee9eabd48aa90f14053723164afee26b66253 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Thu, 3 Oct 2024 13:36:46 +0200 Subject: [PATCH 19/23] e2ee Signed-off-by: Marino Faggiana --- iOSClient/Data/NCManageDatabase+Metadata.swift | 3 +-- .../Extensions/UIAlertController+Extension.swift | 7 +++++++ iOSClient/Networking/NCNetworking+AsyncAwait.swift | 2 +- iOSClient/Networking/NCNetworkingProcess.swift | 2 +- iOSClient/Utility/NCUtility+Image.swift | 12 ++++++------ 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/iOSClient/Data/NCManageDatabase+Metadata.swift b/iOSClient/Data/NCManageDatabase+Metadata.swift index 00ec3e3d4a..129a862b65 100644 --- a/iOSClient/Data/NCManageDatabase+Metadata.swift +++ b/iOSClient/Data/NCManageDatabase+Metadata.swift @@ -555,11 +555,10 @@ extension NCManageDatabase { @discardableResult func addMetadata(_ metadata: tableMetadata) -> tableMetadata? { - do { let realm = try Realm() try realm.write { - realm.add(metadata, update: .all) + realm.add(tableMetadata(value: metadata), update: .all) } } catch let error { NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Could not write to database: \(error)") diff --git a/iOSClient/Extensions/UIAlertController+Extension.swift b/iOSClient/Extensions/UIAlertController+Extension.swift index dcfec1cbba..a403729a98 100644 --- a/iOSClient/Extensions/UIAlertController+Extension.swift +++ b/iOSClient/Extensions/UIAlertController+Extension.swift @@ -35,6 +35,7 @@ extension UIAlertController { static func createFolder(serverUrl: String, account: String, markE2ee: Bool = false, sceneIdentifier: String? = nil, completion: ((_ error: NKError) -> Void)? = nil) -> UIAlertController { let alertController = UIAlertController(title: NSLocalizedString("_create_folder_", comment: ""), message: nil, preferredStyle: .alert) let session = NCSession.shared.getSession(account: account) + let isDirectoryEncrypted = NCUtilityFileSystem().isDirectoryE2EE(session: session, serverUrl: serverUrl) let okAction = UIAlertAction(title: NSLocalizedString("_save_", comment: ""), style: .default, handler: { _ in guard let fileNameFolder = alertController.textFields?.first?.text else { return } @@ -50,6 +51,12 @@ extension UIAlertController { NCContentPresenter().showError(error: createFolderResults.error) } } + } else if isDirectoryEncrypted { + #if !EXTENSION + Task { + await NCNetworkingE2EECreateFolder().createFolder(fileName: fileNameFolder, serverUrl: serverUrl, withPush: true, sceneIdentifier: sceneIdentifier, session: session) + } + #endif } else { let metadataForCreateFolder = NCManageDatabase.shared.createMetadata(fileName: fileNameFolder, fileNameView: fileNameFolder, diff --git a/iOSClient/Networking/NCNetworking+AsyncAwait.swift b/iOSClient/Networking/NCNetworking+AsyncAwait.swift index 0aaa3bff30..cdb8dc3058 100644 --- a/iOSClient/Networking/NCNetworking+AsyncAwait.swift +++ b/iOSClient/Networking/NCNetworking+AsyncAwait.swift @@ -131,7 +131,7 @@ extension NCNetworking { }) } - func createFolderOffline(metadata: tableMetadata) async -> NKError { + func createFolder(metadata: tableMetadata) async -> NKError { await withUnsafeContinuation({ continuation in self.createFolder(fileName: metadata.fileName, serverUrl: metadata.serverUrl, overwrite: true, withPush: false, metadata: metadata, sceneIdentifier: nil, session: NCSession.shared.getSession(account: metadata.account)) { error in continuation.resume(returning: error) diff --git a/iOSClient/Networking/NCNetworkingProcess.swift b/iOSClient/Networking/NCNetworkingProcess.swift index eb4817c360..6622f6400f 100644 --- a/iOSClient/Networking/NCNetworkingProcess.swift +++ b/iOSClient/Networking/NCNetworkingProcess.swift @@ -155,7 +155,7 @@ class NCNetworkingProcess { /// if let metadatasWaitCreateFolder = self.database.getMetadatas(predicate: NSPredicate(format: "status == %d", global.metadataStatusWaitCreateFolder), sortedByKeyPath: "serverUrl", ascending: true), !metadatasWaitCreateFolder.isEmpty { for metadata in metadatasWaitCreateFolder { - let error = await NCNetworking.shared.createFolderOffline(metadata: metadata) + let error = await NCNetworking.shared.createFolder(metadata: metadata) if error != .success { if metadata.sessionError.isEmpty { let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileName diff --git a/iOSClient/Utility/NCUtility+Image.swift b/iOSClient/Utility/NCUtility+Image.swift index f43b438ee3..a54c273abd 100644 --- a/iOSClient/Utility/NCUtility+Image.swift +++ b/iOSClient/Utility/NCUtility+Image.swift @@ -125,14 +125,14 @@ extension NCUtility { func createImageFileFrom(metadata: tableMetadata) { if metadata.classFile != NKCommon.TypeClassFile.image.rawValue, metadata.classFile != NKCommon.TypeClassFile.video.rawValue { return } var image: UIImage? - let fileNamePath1024 = utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView) + let fileNamePath = utilityFileSystem.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView) if image == nil { if metadata.classFile == NKCommon.TypeClassFile.image.rawValue { - image = UIImage(contentsOfFile: fileNamePath1024) + image = UIImage(contentsOfFile: fileNamePath) } else if metadata.classFile == NKCommon.TypeClassFile.video.rawValue { let videoPath = NSTemporaryDirectory() + "tempvideo.mp4" - utilityFileSystem.linkItem(atPath: fileNamePath1024, toPath: videoPath) + utilityFileSystem.linkItem(atPath: fileNamePath, toPath: videoPath) image = imageFromVideo(url: URL(fileURLWithPath: videoPath), at: 0) } } @@ -158,9 +158,9 @@ extension NCUtility { } private func createImageStandard(ocId: String, etag: String, image: UIImage) { - let ext = [global.previewExt512, global.previewExt256] - let size = [global.size512, global.size256] - let compressionQuality = [0.6, 0.7] + let ext = [global.previewExt1024, global.previewExt512, global.previewExt256] + let size = [global.size1024, global.size512, global.size256] + let compressionQuality = [0.5, 0.6, 0.7] for i in 0.. Date: Thu, 3 Oct 2024 15:17:31 +0200 Subject: [PATCH 20/23] e2ee Signed-off-by: Marino Faggiana --- .../UIAlertController+Extension.swift | 4 +- .../NCCollectionViewCommon+SelectTabBar.swift | 5 +- iOSClient/Media/NCMedia+Command.swift | 5 +- iOSClient/Menu/NCContextMenu.swift | 2 +- .../E2EE/NCNetworkingE2EEDelete.swift | 2 - .../Networking/NCNetworking+WebDAV.swift | 76 ++++++++++++++----- iOSClient/Networking/NCNetworking.swift | 2 +- 7 files changed, 66 insertions(+), 30 deletions(-) diff --git a/iOSClient/Extensions/UIAlertController+Extension.swift b/iOSClient/Extensions/UIAlertController+Extension.swift index a403729a98..7aa6258cf3 100644 --- a/iOSClient/Extensions/UIAlertController+Extension.swift +++ b/iOSClient/Extensions/UIAlertController+Extension.swift @@ -129,9 +129,7 @@ extension UIAlertController { preferredStyle: .alert) if canDeleteServer { alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .destructive) { (_: UIAlertAction) in - for metadata in selectedMetadatas { - NCNetworking.shared.deleteMetadata(metadata) - } + NCNetworking.shared.deleteMetadatas(selectedMetadatas, sceneIdentifier: sceneIdentifier) NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSource) completion(false) }) diff --git a/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBar.swift b/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBar.swift index 7605d7f82c..d4ef2c6322 100644 --- a/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBar.swift +++ b/iOSClient/Main/Collection Common/NCCollectionViewCommon+SelectTabBar.swift @@ -44,11 +44,8 @@ extension NCCollectionViewCommon: NCCollectionViewCommonSelectTabBarDelegate { let canDeleteServer = metadatas.allSatisfy { !$0.lock } if canDeleteServer { - let copyMetadatas = metadatas alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .destructive) { _ in - for metadata in copyMetadatas { - NCNetworking.shared.deleteMetadata(metadata) - } + NCNetworking.shared.deleteMetadatas(metadatas, sceneIdentifier: self.controller?.sceneIdentifier) NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSource) self.setEditMode(false) }) diff --git a/iOSClient/Media/NCMedia+Command.swift b/iOSClient/Media/NCMedia+Command.swift index 5a9eb9a6d8..ea709c3815 100644 --- a/iOSClient/Media/NCMedia+Command.swift +++ b/iOSClient/Media/NCMedia+Command.swift @@ -190,6 +190,7 @@ extension NCMedia: NCMediaSelectTabBarDelegate { let ocIds = self.fileSelect.map { $0 } var alertStyle = UIAlertController.Style.actionSheet var indexPaths: [IndexPath] = [] + var metadatas: [tableMetadata] = [] if UIDevice.current.userInterfaceIdiom == .pad { alertStyle = .alert } @@ -203,10 +204,12 @@ extension NCMedia: NCMediaSelectTabBarDelegate { for ocId in ocIds { if let metadata = self.database.getMetadataFromOcId(ocId) { - NCNetworking.shared.deleteMetadata(metadata) + metadatas.append(metadata) } } + NCNetworking.shared.deleteMetadatas(metadatas, sceneIdentifier: self.controller?.sceneIdentifier) + for index in indices { let indexPath = IndexPath(row: index, section: 0) if let cell = self.collectionView.cellForItem(at: indexPath) as? NCMediaCell, diff --git a/iOSClient/Menu/NCContextMenu.swift b/iOSClient/Menu/NCContextMenu.swift index f2e9ef1153..d494b27aba 100644 --- a/iOSClient/Menu/NCContextMenu.swift +++ b/iOSClient/Menu/NCContextMenu.swift @@ -157,7 +157,7 @@ class NCContextMenu: NSObject { } let alertController = UIAlertController(title: nil, message: nil, preferredStyle: alertStyle) alertController.addAction(UIAlertAction(title: NSLocalizedString("_delete_file_", comment: ""), style: .destructive) { _ in - NCNetworking.shared.deleteMetadata(metadata) + NCNetworking.shared.deleteMetadatas([metadata], sceneIdentifier: sceneIdentifier) NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSource) }) alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel) { _ in }) diff --git a/iOSClient/Networking/E2EE/NCNetworkingE2EEDelete.swift b/iOSClient/Networking/E2EE/NCNetworkingE2EEDelete.swift index 11b0261acb..10917856aa 100644 --- a/iOSClient/Networking/E2EE/NCNetworkingE2EEDelete.swift +++ b/iOSClient/Networking/E2EE/NCNetworkingE2EEDelete.swift @@ -105,8 +105,6 @@ class NCNetworkingE2EEDelete: NSObject { // await networkingE2EE.unlock(account: metadata.account, serverUrl: metadata.serverUrl) - NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": [metadata.ocId], "error": NKError()]) - return NKError() } } diff --git a/iOSClient/Networking/NCNetworking+WebDAV.swift b/iOSClient/Networking/NCNetworking+WebDAV.swift index d4086354e5..cbb0e4198f 100644 --- a/iOSClient/Networking/NCNetworking+WebDAV.swift +++ b/iOSClient/Networking/NCNetworking+WebDAV.swift @@ -308,13 +308,12 @@ extension NCNetworking { // MARK: - Delete - func tapHudDeleteCache() { - tapHudStopDeleteCache = true + func tapHudDelete() { + tapHudStopDelete = true } func deleteCache(_ metadata: tableMetadata, sceneIdentifier: String?) async -> (NKError) { let ncHud = NCHud() - var num: Float = 0 func numIncrement() -> Float { @@ -335,24 +334,24 @@ extension NCNetworking { #endif } - self.tapHudStopDeleteCache = false + self.tapHudStopDelete = false if metadata.directory { #if !EXTENSION if let controller = SceneManager.shared.getController(sceneIdentifier: sceneIdentifier) { await MainActor.run { - ncHud.initHudRing(view: controller.view, tapToCancelDetailText: true, tapOperation: tapHudDeleteCache) + ncHud.initHudRing(view: controller.view, tapToCancelDetailText: true, tapOperation: tapHudDelete) } } #endif let serverUrl = metadata.serverUrl + "/" + metadata.fileName let metadatas = self.database.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl BEGINSWITH %@ AND directory == false", metadata.account, serverUrl)) - let numMetadatas = Float(metadatas.count) + let total = Float(metadatas.count) for metadata in metadatas { deleteLocalFile(metadata: metadata) let num = numIncrement() - ncHud.progress(num: num, total: numMetadatas) - if tapHudStopDeleteCache { break } + ncHud.progress(num: num, total: total) + if tapHudStopDelete { break } } #if !EXTENSION ncHud.dismiss() @@ -364,20 +363,61 @@ extension NCNetworking { return .success } - func deleteMetadata(_ metadata: tableMetadata) { - let permission = NCUtility().permissionsContainsString(metadata.permissions, permissions: NCPermissions().permissionCanDelete) - if !metadata.permissions.isEmpty && permission == false { - NCContentPresenter().showInfo(error: NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_no_permission_delete_file_")) - return + func deleteMetadatas(_ metadatas: [tableMetadata], sceneIdentifier: String?) { + var metadatasPlain: [tableMetadata] = [] + var metadatasE2EE: [tableMetadata] = [] + let ncHud = NCHud() + var num: Float = 0 + + func numIncrement() -> Float { + num += 1 + return num } - if metadata.isDirectoryE2EE, NCNetworking.shared.isOnline { - #if !EXTENSION + for metadata in metadatas { + if metadata.isDirectoryE2EE { + metadatasE2EE.append(metadata) + } else { + metadatasPlain.append(metadata) + } + } + +#if !EXTENSION + if !metadatasE2EE.isEmpty { + self.tapHudStopDelete = false + let total = Float(metadatasE2EE.count) + Task { - return await NCNetworkingE2EEDelete().delete(metadata: metadata) + if let controller = SceneManager.shared.getController(sceneIdentifier: sceneIdentifier) { + await MainActor.run { + ncHud.initHudRing(view: controller.view, tapToCancelDetailText: true, tapOperation: tapHudDelete) + } + } + + var ocIdDeleted: [String] = [] + var error = NKError() + for metadata in metadatasE2EE where error == .success { + error = await NCNetworkingE2EEDelete().delete(metadata: metadata) + if error == .success { + ocIdDeleted.append(metadata.ocId) + } + let num = numIncrement() + ncHud.progress(num: num, total: total) + if tapHudStopDelete { break } + } + + ncHud.dismiss() + NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDeleteFile, userInfo: ["ocId": ocIdDeleted, "error": error]) + } + } +#endif + + for metadata in metadatasPlain { + let permission = NCUtility().permissionsContainsString(metadata.permissions, permissions: NCPermissions().permissionCanDelete) + if !metadata.permissions.isEmpty && permission == false { + NCContentPresenter().showInfo(error: NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_no_permission_delete_file_")) + return } - #endif - } else { if metadata.status == global.metadataStatusWaitCreateFolder { let metadatas = database.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl BEGINSWITH %@", metadata.account, metadata.serverUrl)) diff --git a/iOSClient/Networking/NCNetworking.swift b/iOSClient/Networking/NCNetworking.swift index dd1feb7735..e22b68e36f 100644 --- a/iOSClient/Networking/NCNetworking.swift +++ b/iOSClient/Networking/NCNetworking.swift @@ -75,7 +75,7 @@ class NCNetworking: NSObject, NextcloudKitDelegate { weak var certificateDelegate: ClientCertificateDelegate? var p12Data: Data? var p12Password: String? - var tapHudStopDeleteCache = false + var tapHudStopDelete = false var isOffline: Bool { return networkReachability == NKCommon.TypeReachability.notReachable || networkReachability == NKCommon.TypeReachability.unknown From 4ed77017d45846222e4884f14be95aece9158c13 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Thu, 3 Oct 2024 15:26:58 +0200 Subject: [PATCH 21/23] cod Signed-off-by: Marino Faggiana --- iOSClient/Extensions/UIAlertController+Extension.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iOSClient/Extensions/UIAlertController+Extension.swift b/iOSClient/Extensions/UIAlertController+Extension.swift index 7aa6258cf3..2062892abf 100644 --- a/iOSClient/Extensions/UIAlertController+Extension.swift +++ b/iOSClient/Extensions/UIAlertController+Extension.swift @@ -234,7 +234,7 @@ extension UIAlertController { let cancelAction = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel) alertController.addTextField { textField in - textField.text = metadata.fileName + textField.text = metadata.fileNameView textField.autocapitalizationType = .words } From ba886ed9a1bee58495172d2b642c6841092719a9 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Thu, 3 Oct 2024 15:37:37 +0200 Subject: [PATCH 22/23] checkoffline Signed-off-by: Marino Faggiana --- .../UIAlertController+Extension.swift | 11 +--------- .../Networking/NCNetworking+WebDAV.swift | 20 ++++++++++++++++++- .../en.lproj/Localizable.strings | 1 + 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/iOSClient/Extensions/UIAlertController+Extension.swift b/iOSClient/Extensions/UIAlertController+Extension.swift index 2062892abf..c0b277e33b 100644 --- a/iOSClient/Extensions/UIAlertController+Extension.swift +++ b/iOSClient/Extensions/UIAlertController+Extension.swift @@ -215,16 +215,7 @@ extension UIAlertController { return } - if metadata.isDirectoryE2EE, NCNetworking.shared.isOnline { - Task { - let error = await NCNetworkingE2EERename().rename(metadata: metadata, fileNameNew: fileNameNew) - if error != .success { - NCContentPresenter().showError(error: error) - } - } - } else { - NCNetworking.shared.renameMetadata(metadata, fileNameNew: fileNameNew) - } + NCNetworking.shared.renameMetadata(metadata, fileNameNew: fileNameNew) NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSource, userInfo: ["serverUrl": metadata.serverUrl]) }) diff --git a/iOSClient/Networking/NCNetworking+WebDAV.swift b/iOSClient/Networking/NCNetworking+WebDAV.swift index cbb0e4198f..a66c9cb660 100644 --- a/iOSClient/Networking/NCNetworking+WebDAV.swift +++ b/iOSClient/Networking/NCNetworking+WebDAV.swift @@ -384,6 +384,10 @@ extension NCNetworking { #if !EXTENSION if !metadatasE2EE.isEmpty { + if isOffline { + return NCContentPresenter().showInfo(error: NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_offline_not_allowed_")) + } + self.tapHudStopDelete = false let total = Float(metadatasE2EE.count) @@ -440,7 +444,21 @@ extension NCNetworking { return } - self.database.renameMetadata(fileNameNew: fileNameNew, ocId: metadata.ocId, status: NCGlobal.shared.metadataStatusWaitRename) + if metadata.isDirectoryE2EE { +#if !EXTENSION + if isOffline { + return NCContentPresenter().showInfo(error: NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_offline_not_allowed_")) + } + Task { + let error = await NCNetworkingE2EERename().rename(metadata: metadata, fileNameNew: fileNameNew) + if error != .success { + NCContentPresenter().showError(error: error) + } + } +#endif + } else { + self.database.renameMetadata(fileNameNew: fileNameNew, ocId: metadata.ocId, status: NCGlobal.shared.metadataStatusWaitRename) + } } // MARK: - Move diff --git a/iOSClient/Supporting Files/en.lproj/Localizable.strings b/iOSClient/Supporting Files/en.lproj/Localizable.strings index 0b3b0e1f85..656237fd5c 100644 --- a/iOSClient/Supporting Files/en.lproj/Localizable.strings +++ b/iOSClient/Supporting Files/en.lproj/Localizable.strings @@ -1032,6 +1032,7 @@ "_creating_db_photo_progress" = "Creating photo archive in progress … keep the application active"; "_account_unauthorized_" = "Warning, %@, you are not authorized, your account has been deleted, if you have changed your password, re-authenticate."; "_folder_offline_desc_" = "Even without an internet connection, you can organize your folders, create files. Once you're back online, your pending actions will automatically sync."; +"_offline_not_allowed_" = "This operation is not allowed in offline mode"; // Tip "_tip_pdf_thumbnails_" = "Swipe left from the right edge of the screen to show the thumbnails."; From 40370fd684eccf995311b61815b3c7532debc509 Mon Sep 17 00:00:00 2001 From: Marino Faggiana Date: Thu, 3 Oct 2024 15:42:04 +0200 Subject: [PATCH 23/23] e2ee Signed-off-by: Marino Faggiana --- iOSClient/Extensions/UIAlertController+Extension.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/iOSClient/Extensions/UIAlertController+Extension.swift b/iOSClient/Extensions/UIAlertController+Extension.swift index c0b277e33b..bc70ae6501 100644 --- a/iOSClient/Extensions/UIAlertController+Extension.swift +++ b/iOSClient/Extensions/UIAlertController+Extension.swift @@ -40,6 +40,9 @@ extension UIAlertController { let okAction = UIAlertAction(title: NSLocalizedString("_save_", comment: ""), style: .default, handler: { _ in guard let fileNameFolder = alertController.textFields?.first?.text else { return } if markE2ee { + if NCNetworking.shared.isOffline { + return NCContentPresenter().showInfo(error: NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_offline_not_allowed_")) + } Task { let createFolderResults = await NCNetworking.shared.createFolder(serverUrlFileName: serverUrl + "/" + fileNameFolder, account: session.account) if createFolderResults.error == .success { @@ -52,6 +55,9 @@ extension UIAlertController { } } } else if isDirectoryEncrypted { + if NCNetworking.shared.isOffline { + return NCContentPresenter().showInfo(error: NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_offline_not_allowed_")) + } #if !EXTENSION Task { await NCNetworkingE2EECreateFolder().createFolder(fileName: fileNameFolder, serverUrl: serverUrl, withPush: true, sceneIdentifier: sceneIdentifier, session: session)