Do not delete imported host on error

Could be an app bug or something to be implemented in the future.
This commit is contained in:
Davide De Rosa 2019-07-08 08:44:37 +02:00
parent 41ed10e76e
commit f543b0d753
3 changed files with 9 additions and 5 deletions

View File

@ -106,7 +106,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
let passphraseCancelBlock = {
_ = try? FileManager.default.removeItem(at: url)
}
guard let parsingResult = OpenVPN.ConfigurationParser.Result.from(url, withErrorAlertIn: target, passphrase: passphrase, passphraseBlock: passphraseBlock, passphraseCancelBlock: passphraseCancelBlock) else {
guard let parsingResult = OpenVPN.ConfigurationParser.Result.from(url, withErrorAlertIn: target, passphrase: passphrase, removeOnError: true, passphraseBlock: passphraseBlock, passphraseCancelBlock: passphraseCancelBlock) else {
return true
}
if let warning = parsingResult.warning {

View File

@ -32,7 +32,7 @@ import PassepartoutCore
private let log = SwiftyBeaver.self
extension OpenVPN.ConfigurationParser.Result {
static func from(_ url: URL, withErrorAlertIn viewController: UIViewController, passphrase: String?,
static func from(_ url: URL, withErrorAlertIn viewController: UIViewController, passphrase: String?, removeOnError: Bool,
passphraseBlock: @escaping (String) -> Void, passphraseCancelBlock: (() -> Void)?) -> OpenVPN.ConfigurationParser.Result? {
let result: OpenVPN.ConfigurationParser.Result
@ -62,13 +62,17 @@ extension OpenVPN.ConfigurationParser.Result {
default:
let message = localizedMessage(forError: e)
alertImportError(url: url, in: viewController, withMessage: message)
try? fm.removeItem(at: url)
if removeOnError {
try? fm.removeItem(at: url)
}
}
return nil
} catch let e {
let message = localizedMessage(forError: e)
alertImportError(url: url, in: viewController, withMessage: message)
try? fm.removeItem(at: url)
if removeOnError {
try? fm.removeItem(at: url)
}
return nil
}
return result

View File

@ -88,7 +88,7 @@ class ImportedHostsViewController: UITableViewController {
}
self.perform(segue: StoryboardSegue.Organizer.importHostSegueIdentifier, sender: cell)
}
guard let parsingResult = OpenVPN.ConfigurationParser.Result.from(url, withErrorAlertIn: self, passphrase: passphrase, passphraseBlock: passphraseBlock, passphraseCancelBlock: nil) else {
guard let parsingResult = OpenVPN.ConfigurationParser.Result.from(url, withErrorAlertIn: self, passphrase: passphrase, removeOnError: false, passphraseBlock: passphraseBlock, passphraseCancelBlock: nil) else {
deselectSelectedRow()
return false
}