From dcecc84bdaeed0b368952376bd18cc14ddcf9191 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sat, 27 Oct 2018 12:39:22 +0200 Subject: [PATCH 1/6] Remove .ovpn of deleted profile --- .../ConnectionService+Configurations.swift | 22 +++++++++++++------ .../Sources/Model/ConnectionService.swift | 3 +++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Passepartout/Sources/Model/ConnectionService+Configurations.swift b/Passepartout/Sources/Model/ConnectionService+Configurations.swift index d17ce951..625da0d3 100644 --- a/Passepartout/Sources/Model/ConnectionService+Configurations.swift +++ b/Passepartout/Sources/Model/ConnectionService+Configurations.swift @@ -29,25 +29,33 @@ import SwiftyBeaver private let log = SwiftyBeaver.self extension ConnectionService { - func save(configurationURL: URL, for profile: ConnectionProfile) throws -> URL { - let destinationURL = targetConfigurationURL(for: profile) + func save(configurationURL: URL, for key: ProfileKey) throws -> URL { + let destinationURL = targetConfigurationURL(for: key) let fm = FileManager.default try? fm.removeItem(at: destinationURL) try fm.copyItem(at: configurationURL, to: destinationURL) return destinationURL } - func configurationURL(for profile: ConnectionProfile) -> URL? { - let url = targetConfigurationURL(for: profile) + func save(configurationURL: URL, for profile: ConnectionProfile) throws -> URL { + return try save(configurationURL: configurationURL, for: ProfileKey(profile)) + } + + func configurationURL(for key: ProfileKey) -> URL? { + let url = targetConfigurationURL(for: key) guard FileManager.default.fileExists(atPath: url.path) else { return nil } return url } + + func configurationURL(for profile: ConnectionProfile) -> URL? { + return configurationURL(for: ProfileKey(profile)) + } - private func targetConfigurationURL(for profile: ConnectionProfile) -> URL { - let contextURL = ConnectionService.ProfileKey(profile).contextURL(in: self) - return contextURL.appendingPathComponent(profile.id).appendingPathExtension("ovpn") + private func targetConfigurationURL(for key: ProfileKey) -> URL { + let contextURL = key.contextURL(in: self) + return contextURL.appendingPathComponent(key.id).appendingPathExtension("ovpn") } func pendingConfigurationURLs() -> [URL] { diff --git a/Passepartout/Sources/Model/ConnectionService.swift b/Passepartout/Sources/Model/ConnectionService.swift index b17e21a9..26969aa4 100644 --- a/Passepartout/Sources/Model/ConnectionService.swift +++ b/Passepartout/Sources/Model/ConnectionService.swift @@ -248,6 +248,9 @@ class ConnectionService: Codable { for key in pendingRemoval { let url = key.profileURL(in: self) try? fm.removeItem(at: url) + if let cfg = configurationURL(for: key) { + try? fm.removeItem(at: cfg) + } } for entry in cache.values { if let profile = entry as? ProviderConnectionProfile { From 9f951fc68bfe619acfe6e24312d0ada3324c5297 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sat, 27 Oct 2018 12:40:45 +0200 Subject: [PATCH 2/6] Delete .ovpn after import --- .../Scenes/Organizer/WizardHostViewController.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Passepartout-iOS/Scenes/Organizer/WizardHostViewController.swift b/Passepartout-iOS/Scenes/Organizer/WizardHostViewController.swift index db2c4b73..6f044c61 100644 --- a/Passepartout-iOS/Scenes/Organizer/WizardHostViewController.swift +++ b/Passepartout-iOS/Scenes/Organizer/WizardHostViewController.swift @@ -134,6 +134,9 @@ class WizardHostViewController: UITableViewController, TableModelHost, Wizard { do { let savedURL = try TransientStore.shared.service.save(configurationURL: url, for: profile) log.debug("Associated .ovpn configuration file to profile '\(profile.id)': \(savedURL)") + + // can now delete imported file + try? FileManager.default.removeItem(at: url) } catch let e { log.error("Could not associate .ovpn configuration file to profile: \(e)") } From 0d23187eef6c035d668359ea7a02acaf23460a79 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sat, 27 Oct 2018 13:15:26 +0200 Subject: [PATCH 3/6] Delete unparsable .ovpn --- Passepartout-iOS/AppDelegate.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Passepartout-iOS/AppDelegate.swift b/Passepartout-iOS/AppDelegate.swift index 795ea6b4..9714d8f1 100644 --- a/Passepartout-iOS/AppDelegate.swift +++ b/Passepartout-iOS/AppDelegate.swift @@ -90,7 +90,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele fatalError("No window.rootViewController?") } + let fm = FileManager.default guard let parsedFile = ParsedFile.from(url, withErrorAlertIn: root) else { + try? fm.removeItem(at: url) return true } From 42c94c3a1418321a4f2416a70edc9da1939605f9 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sat, 27 Oct 2018 13:20:23 +0200 Subject: [PATCH 4/6] Delete openURL .ovpn on Cancel --- Passepartout-iOS/AppDelegate.swift | 2 ++ .../Scenes/Organizer/WizardHostViewController.swift | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/Passepartout-iOS/AppDelegate.swift b/Passepartout-iOS/AppDelegate.swift index 9714d8f1..ddd18ddb 100644 --- a/Passepartout-iOS/AppDelegate.swift +++ b/Passepartout-iOS/AppDelegate.swift @@ -99,6 +99,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele // already presented: update parsed configuration if let nav = root.presentedViewController as? UINavigationController, let wizard = nav.topViewController as? WizardHostViewController { wizard.parsedFile = parsedFile + wizard.removesConfigurationOnCancel = true return true } @@ -108,6 +109,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele fatalError("Expected WizardHostViewController from storyboard") } wizard.parsedFile = parsedFile + wizard.removesConfigurationOnCancel = true // best effort to delegate to main vc let split = root as? UISplitViewController diff --git a/Passepartout-iOS/Scenes/Organizer/WizardHostViewController.swift b/Passepartout-iOS/Scenes/Organizer/WizardHostViewController.swift index 6f044c61..3c7531db 100644 --- a/Passepartout-iOS/Scenes/Organizer/WizardHostViewController.swift +++ b/Passepartout-iOS/Scenes/Organizer/WizardHostViewController.swift @@ -41,6 +41,8 @@ class WizardHostViewController: UITableViewController, TableModelHost, Wizard { useSuggestedTitle() } } + + var removesConfigurationOnCancel = false private var createdProfile: HostConnectionProfile? @@ -148,6 +150,9 @@ class WizardHostViewController: UITableViewController, TableModelHost, Wizard { } @IBAction private func close() { + if removesConfigurationOnCancel, let url = parsedFile?.url { + try? FileManager.default.removeItem(at: url) + } dismiss(animated: true, completion: nil) } } From 05d745ad6dc65f7e42092725c0de01c3ceb90710 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sat, 27 Oct 2018 13:21:03 +0200 Subject: [PATCH 5/6] Remove unused code --- Passepartout-iOS/Global/Macros.swift | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Passepartout-iOS/Global/Macros.swift b/Passepartout-iOS/Global/Macros.swift index c28a1e24..d173fe66 100644 --- a/Passepartout-iOS/Global/Macros.swift +++ b/Passepartout-iOS/Global/Macros.swift @@ -33,10 +33,6 @@ class Macros { static func actionSheet(_ title: String?, _ message: String?) -> UIAlertController { return UIAlertController(title: title, message: message, preferredStyle: .actionSheet) } - - static var isDeviceNonPlus: Bool { - return (UI_USER_INTERFACE_IDIOM() == .phone) && (UIScreen.main.scale < 3.0) - } } extension UIAlertController { From cda53bc4f1c820350fce4d26e100b769cdf88036 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sat, 27 Oct 2018 13:30:08 +0200 Subject: [PATCH 6/6] Clean up Inbox on migration --- .../Sources/Model/ConnectionService+Migration.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Passepartout/Sources/Model/ConnectionService+Migration.swift b/Passepartout/Sources/Model/ConnectionService+Migration.swift index 4a9066ca..03513539 100644 --- a/Passepartout/Sources/Model/ConnectionService+Migration.swift +++ b/Passepartout/Sources/Model/ConnectionService+Migration.swift @@ -45,7 +45,7 @@ extension ConnectionService { throw ApplicationError.migration } - // replace migration logic here + // put migration logic here // TODO: remove this code after 1.0 release let build = json["build"] as? Int ?? 0 if build <= 1084 { @@ -55,6 +55,11 @@ extension ConnectionService { try migrateHostProfileConfigurations() try migrateSplitProfileSerialization(&json) } + if build <= 1107 { + let fm = FileManager.default + let inbox = fm.userURL(for: .documentDirectory, appending: "Inbox") + try? fm.removeItem(at: inbox) + } return try JSONSerialization.data(withJSONObject: json, options: []) }