From fd30ce0e0da9d3adbc2d5e3d1d38ec48b6adaf15 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Thu, 1 Nov 2018 01:42:29 +0530 Subject: [PATCH] Importing: Error out on duplicate name --- .../WireGuard/UI/iOS/TunnelsListTableViewController.swift | 8 +++++--- 1 file 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") } } }