Skip to content

Commit

Permalink
Do not overwrite existing file with a new created textfile #460
Browse files Browse the repository at this point in the history
  • Loading branch information
Marino Faggiana authored and Marino Faggiana committed Jan 16, 2018
1 parent 02c54e5 commit c74d6f1
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions iOSClient/Create/CCCreateCloud.swift
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,34 @@ class CreateFormUploadFile: XLFormViewController, CCMoveDelegate {
fileNameSave = (name as! NSString).deletingPathExtension + ".txt"
}

guard let directoryID = NCManageDatabase.sharedInstance.getDirectoryID(self.serverUrl) else {
return
}
let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account = %@ AND directoryID = %@ AND fileNameView = %@", appDelegate.activeAccount, directoryID, fileNameSave))

if (metadata != nil) {

let alertController = UIAlertController(title: fileNameSave, message: NSLocalizedString("_file_already_exists_", comment: ""), preferredStyle: .alert)

let cancelAction = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .default) { (action:UIAlertAction) in
}

let overwriteAction = UIAlertAction(title: NSLocalizedString("_overwrite_", comment: ""), style: .cancel) { (action:UIAlertAction) in
self.dismissAndUpload(fileNameSave)
}

alertController.addAction(cancelAction)
alertController.addAction(overwriteAction)

self.present(alertController, animated: true, completion:nil)
} else {

dismissAndUpload(fileNameSave)
}
}

func dismissAndUpload(_ fileNameSave: String) {

self.dismiss(animated: true, completion: {

let data = self.text.data(using: .utf8)
Expand Down

0 comments on commit c74d6f1

Please sign in to comment.