|
@@ -269,7 +269,7 @@ import NCCommunication
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- @objc func deleteMetadataPlain(_ metadata: tableMetadata, completion: @escaping (_ errorCode: Int, _ errorDescription: String)->()) {
|
|
|
|
|
|
+ private func deleteMetadataPlain(_ metadata: tableMetadata, completion: @escaping (_ errorCode: Int, _ errorDescription: String)->()) {
|
|
|
|
|
|
// verify permission
|
|
// verify permission
|
|
let permission = NCUtility.sharedInstance.permissionsContainsString(metadata.permissions, permissions: k_permission_can_delete)
|
|
let permission = NCUtility.sharedInstance.permissionsContainsString(metadata.permissions, permissions: k_permission_can_delete)
|
|
@@ -308,7 +308,7 @@ import NCCommunication
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- @objc func deleteMetadataE2EE(_ metadata: tableMetadata, directory: tableDirectory, user: String, userID: String, password: String, url: String, completion: @escaping (_ errorCode: Int, _ errorDescription: String)->()) {
|
|
|
|
|
|
+ private func deleteMetadataE2EE(_ metadata: tableMetadata, directory: tableDirectory, user: String, userID: String, password: String, url: String, completion: @escaping (_ errorCode: Int, _ errorDescription: String)->()) {
|
|
|
|
|
|
DispatchQueue.global().async {
|
|
DispatchQueue.global().async {
|
|
// LOCK FOLDER
|
|
// LOCK FOLDER
|
|
@@ -365,4 +365,93 @@ import NCCommunication
|
|
completion(errorCode, description)
|
|
completion(errorCode, description)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @objc func renameMetadata(_ metadata: tableMetadata, fileNameNew: String, viewController: UIViewController?, completion: @escaping (_ errorCode: Int, _ errorDescription: String)->()) {
|
|
|
|
+
|
|
|
|
+ let directory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", metadata.account, metadata.serverUrl))
|
|
|
|
+
|
|
|
|
+ if directory != nil && directory?.e2eEncrypted == true {
|
|
|
|
+ //self.deleteMetadataE2EE(metadata, directory: directory!, user: user, userID: userID, password: password, url: url, completion: completion)
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ renameMetadataPlain(metadata, fileNameNew: fileNameNew, viewController: viewController, completion: completion)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private func renameMetadataPlain(_ metadata: tableMetadata, fileNameNew: String, viewController: UIViewController?, completion: @escaping (_ errorCode: Int, _ errorDescription: String)->()) {
|
|
|
|
+
|
|
|
|
+ let permission = NCUtility.sharedInstance.permissionsContainsString(metadata.permissions, permissions: k_permission_can_rename)
|
|
|
|
+ if !(metadata.permissions == "") && !permission {
|
|
|
|
+ NCContentPresenter.shared.messageNotification("_error_", description: "_no_permission_modify_file_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: Int(k_CCErrorInternalError))
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ guard let fileNameNew = CCUtility.removeForbiddenCharactersServer(fileNameNew) else { return }
|
|
|
|
+ if fileNameNew.count == 0 || fileNameNew == metadata.fileNameView { return }
|
|
|
|
+
|
|
|
|
+ // Verify if exists the fileName TO
|
|
|
|
+ let serverUrlFileName = metadata.serverUrl + "/" + fileNameNew
|
|
|
|
+ NCCommunication.sharedInstance.readFileOrFolder(serverUrlFileName: serverUrlFileName, depth: "0", account: metadata.account) { (account ,files, errorCode, errorDescription) in
|
|
|
|
+
|
|
|
|
+ if errorCode == 0 {
|
|
|
|
+
|
|
|
|
+ let alertController = UIAlertController(title: NSLocalizedString("_error_", comment: ""), message: NSLocalizedString("_file_already_exists_", comment: ""), preferredStyle: .alert)
|
|
|
|
+ alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default) { (action:UIAlertAction) in })
|
|
|
|
+ viewController?.present(alertController, animated: true, completion:nil)
|
|
|
|
+
|
|
|
|
+ } else if errorCode == kOCErrorServerPathNotFound {
|
|
|
|
+
|
|
|
|
+ let fileNamePath = metadata.serverUrl + "/" + metadata.fileName
|
|
|
|
+ let fileNameToPath = metadata.serverUrl + "/" + fileNameNew
|
|
|
|
+
|
|
|
|
+ NCCommunication.sharedInstance.moveFileOrFolder(serverUrlFileNameSource: fileNamePath, serverUrlFileNameDestination: fileNameToPath, account: metadata.account) { (account, errorCode, errorDescription) in
|
|
|
|
+
|
|
|
|
+ if errorCode == 0 {
|
|
|
|
+
|
|
|
|
+ if let metadataNew = NCManageDatabase.sharedInstance.renameMetadata(fileNameTo: fileNameNew, ocId: metadata.ocId) {
|
|
|
|
+ let userInfo: [String : Any] = ["metadata": metadata, "metadataNew": metadataNew, "errorCode": Int(errorCode), "errorDescription": ""]
|
|
|
|
+ NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_renameFile), object: nil, userInfo: userInfo)
|
|
|
|
+ }
|
|
|
|
+ NCManageDatabase.sharedInstance.renameMedia(fileNameTo: fileNameNew, ocId: metadata.ocId)
|
|
|
|
+
|
|
|
|
+ if metadata.directory {
|
|
|
|
+
|
|
|
|
+ let serverUrl = CCUtility.stringAppendServerUrl(metadata.serverUrl, addFileName: metadata.fileName)!
|
|
|
|
+ let serverUrlTo = CCUtility.stringAppendServerUrl(metadata.serverUrl, addFileName: fileNameNew)!
|
|
|
|
+ if let directory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", metadata.account, metadata.serverUrl)) {
|
|
|
|
+
|
|
|
|
+ NCManageDatabase.sharedInstance.setDirectory(serverUrl: serverUrl, serverUrlTo: serverUrlTo, etag: "", ocId: nil, encrypted: directory.e2eEncrypted, richWorkspace: nil, account: metadata.account)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ NCManageDatabase.sharedInstance.setLocalFile(ocId: metadata.ocId, date: nil, exifDate: nil, exifLatitude: nil, exifLongitude: nil, fileName: fileNameNew, etag: nil)
|
|
|
|
+ // Move file system
|
|
|
|
+ let atPath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId) + "/" + metadata.fileName
|
|
|
|
+ let toPath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId) + "/" + fileNameNew
|
|
|
|
+ do {
|
|
|
|
+ try FileManager.default.moveItem(atPath: atPath, toPath: toPath)
|
|
|
|
+ } catch { }
|
|
|
|
+ let atPathIcon = CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileName)!
|
|
|
|
+ let toPathIcon = CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: fileNameNew)!
|
|
|
|
+ do {
|
|
|
|
+ try FileManager.default.moveItem(atPath: atPathIcon, toPath: toPathIcon)
|
|
|
|
+ } catch { }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
|
|
|
|
+
|
|
|
|
+ let userInfo: [String : Any] = ["metadata": metadata, "errorCode": Int(errorCode), "errorDescription": errorDescription!]
|
|
|
|
+ NotificationCenter.default.post(name: Notification.Name.init(rawValue: k_notificationCenter_renameFile), object: nil, userInfo: userInfo)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|