aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-11-01 01:42:29 +0530
committerRoopesh Chander <roop@roopc.net>2018-11-01 11:45:44 +0530
commit066449b2073d82e2f1464ca91491839e0a53ba64 (patch)
tree17ea9d00226f3e99ac2710271797fd447311f6b9
parentQR Code: Error out on duplicate name (diff)
downloadwireguard-apple-066449b2073d82e2f1464ca91491839e0a53ba64.tar.xz
wireguard-apple-066449b2073d82e2f1464ca91491839e0a53ba64.zip
Importing: Error out on duplicate name
Signed-off-by: Roopesh Chander <roop@roopc.net>
-rw-r--r--WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift8
1 files changed, 5 insertions, 3 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
index 780f4d5..3fa05f5 100644
--- a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift
@@ -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")
}
}
}