Importing: Error out on duplicate name

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2018-11-01 01:42:29 +05:30
parent bede8a17ad
commit 066449b207
1 changed files with 5 additions and 3 deletions

View File

@ -141,8 +141,8 @@ class TunnelsListTableViewController: UITableViewController {
if let fileContents = try? String(contentsOf: url),
let tunnelConfiguration = try? WgQuickConfigFileParser.parse(fileContents, name: fileBaseName) {
tunnelsManager?.add(tunnelConfiguration: tunnelConfiguration) { (tunnel, error) in
if (error != nil) {
print("Error adding configuration: \(tunnelConfiguration.interface.name)")
if let error = error {
ErrorPresenter.showErrorAlert(error: error, from: self)
}
}
} else {
@ -162,7 +162,9 @@ class TunnelsListTableViewController: UITableViewController {
var numberOfConfigFilesWithErrors = 0
var tunnelConfigurationsToAdd: [TunnelConfiguration] = []
for unarchivedFile in unarchivedFiles {
guard let tunnelsManager = tunnelsManager else { return }
if let fileBaseName = URL(string: unarchivedFile.fileName)?.deletingPathExtension().lastPathComponent,
(!tunnelsManager.containsTunnel(named: fileBaseName)),
let fileContents = String(data: unarchivedFile.contents, encoding: .utf8),
let tunnelConfiguration = try? WgQuickConfigFileParser.parse(fileContents, name: fileBaseName) {
tunnelConfigurationsToAdd.append(tunnelConfiguration)
@ -180,7 +182,7 @@ class TunnelsListTableViewController: UITableViewController {
}
if (numberOfConfigFilesWithErrors > 0) {
showErrorAlert(title: "Could not import \(numberOfConfigFilesWithErrors + numberOfTunnelsRemainingAfterError) files",
message: "\(numberOfConfigFilesWithErrors) of \(unarchivedFiles.count) files contained errors and were not imported")
message: "\(numberOfConfigFilesWithErrors) of \(unarchivedFiles.count) files contained errors or duplicate names and were not imported")
}
}
}