Merge branch 'delete-stale-configuration-files'
This commit is contained in:
commit
9cb8cf92ca
|
@ -90,13 +90,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
|
||||||
fatalError("No window.rootViewController?")
|
fatalError("No window.rootViewController?")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let fm = FileManager.default
|
||||||
guard let parsedFile = ParsedFile.from(url, withErrorAlertIn: root) else {
|
guard let parsedFile = ParsedFile.from(url, withErrorAlertIn: root) else {
|
||||||
|
try? fm.removeItem(at: url)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// already presented: update parsed configuration
|
// already presented: update parsed configuration
|
||||||
if let nav = root.presentedViewController as? UINavigationController, let wizard = nav.topViewController as? WizardHostViewController {
|
if let nav = root.presentedViewController as? UINavigationController, let wizard = nav.topViewController as? WizardHostViewController {
|
||||||
wizard.parsedFile = parsedFile
|
wizard.parsedFile = parsedFile
|
||||||
|
wizard.removesConfigurationOnCancel = true
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,6 +109,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
|
||||||
fatalError("Expected WizardHostViewController from storyboard")
|
fatalError("Expected WizardHostViewController from storyboard")
|
||||||
}
|
}
|
||||||
wizard.parsedFile = parsedFile
|
wizard.parsedFile = parsedFile
|
||||||
|
wizard.removesConfigurationOnCancel = true
|
||||||
|
|
||||||
// best effort to delegate to main vc
|
// best effort to delegate to main vc
|
||||||
let split = root as? UISplitViewController
|
let split = root as? UISplitViewController
|
||||||
|
|
|
@ -33,10 +33,6 @@ class Macros {
|
||||||
static func actionSheet(_ title: String?, _ message: String?) -> UIAlertController {
|
static func actionSheet(_ title: String?, _ message: String?) -> UIAlertController {
|
||||||
return UIAlertController(title: title, message: message, preferredStyle: .actionSheet)
|
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 {
|
extension UIAlertController {
|
||||||
|
|
|
@ -42,6 +42,8 @@ class WizardHostViewController: UITableViewController, TableModelHost, Wizard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var removesConfigurationOnCancel = false
|
||||||
|
|
||||||
private var createdProfile: HostConnectionProfile?
|
private var createdProfile: HostConnectionProfile?
|
||||||
|
|
||||||
weak var delegate: WizardDelegate?
|
weak var delegate: WizardDelegate?
|
||||||
|
@ -134,6 +136,9 @@ class WizardHostViewController: UITableViewController, TableModelHost, Wizard {
|
||||||
do {
|
do {
|
||||||
let savedURL = try TransientStore.shared.service.save(configurationURL: url, for: profile)
|
let savedURL = try TransientStore.shared.service.save(configurationURL: url, for: profile)
|
||||||
log.debug("Associated .ovpn configuration file to profile '\(profile.id)': \(savedURL)")
|
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 {
|
} catch let e {
|
||||||
log.error("Could not associate .ovpn configuration file to profile: \(e)")
|
log.error("Could not associate .ovpn configuration file to profile: \(e)")
|
||||||
}
|
}
|
||||||
|
@ -145,6 +150,9 @@ class WizardHostViewController: UITableViewController, TableModelHost, Wizard {
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction private func close() {
|
@IBAction private func close() {
|
||||||
|
if removesConfigurationOnCancel, let url = parsedFile?.url {
|
||||||
|
try? FileManager.default.removeItem(at: url)
|
||||||
|
}
|
||||||
dismiss(animated: true, completion: nil)
|
dismiss(animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,25 +29,33 @@ import SwiftyBeaver
|
||||||
private let log = SwiftyBeaver.self
|
private let log = SwiftyBeaver.self
|
||||||
|
|
||||||
extension ConnectionService {
|
extension ConnectionService {
|
||||||
func save(configurationURL: URL, for profile: ConnectionProfile) throws -> URL {
|
func save(configurationURL: URL, for key: ProfileKey) throws -> URL {
|
||||||
let destinationURL = targetConfigurationURL(for: profile)
|
let destinationURL = targetConfigurationURL(for: key)
|
||||||
let fm = FileManager.default
|
let fm = FileManager.default
|
||||||
try? fm.removeItem(at: destinationURL)
|
try? fm.removeItem(at: destinationURL)
|
||||||
try fm.copyItem(at: configurationURL, to: destinationURL)
|
try fm.copyItem(at: configurationURL, to: destinationURL)
|
||||||
return destinationURL
|
return destinationURL
|
||||||
}
|
}
|
||||||
|
|
||||||
func configurationURL(for profile: ConnectionProfile) -> URL? {
|
func save(configurationURL: URL, for profile: ConnectionProfile) throws -> URL {
|
||||||
let url = targetConfigurationURL(for: profile)
|
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 {
|
guard FileManager.default.fileExists(atPath: url.path) else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
|
|
||||||
private func targetConfigurationURL(for profile: ConnectionProfile) -> URL {
|
func configurationURL(for profile: ConnectionProfile) -> URL? {
|
||||||
let contextURL = ConnectionService.ProfileKey(profile).contextURL(in: self)
|
return configurationURL(for: ProfileKey(profile))
|
||||||
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] {
|
func pendingConfigurationURLs() -> [URL] {
|
||||||
|
|
|
@ -45,7 +45,7 @@ extension ConnectionService {
|
||||||
throw ApplicationError.migration
|
throw ApplicationError.migration
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace migration logic here
|
// put migration logic here
|
||||||
// TODO: remove this code after 1.0 release
|
// TODO: remove this code after 1.0 release
|
||||||
let build = json["build"] as? Int ?? 0
|
let build = json["build"] as? Int ?? 0
|
||||||
if build <= 1084 {
|
if build <= 1084 {
|
||||||
|
@ -55,6 +55,11 @@ extension ConnectionService {
|
||||||
try migrateHostProfileConfigurations()
|
try migrateHostProfileConfigurations()
|
||||||
try migrateSplitProfileSerialization(&json)
|
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: [])
|
return try JSONSerialization.data(withJSONObject: json, options: [])
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,6 +248,9 @@ class ConnectionService: Codable {
|
||||||
for key in pendingRemoval {
|
for key in pendingRemoval {
|
||||||
let url = key.profileURL(in: self)
|
let url = key.profileURL(in: self)
|
||||||
try? fm.removeItem(at: url)
|
try? fm.removeItem(at: url)
|
||||||
|
if let cfg = configurationURL(for: key) {
|
||||||
|
try? fm.removeItem(at: cfg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for entry in cache.values {
|
for entry in cache.values {
|
||||||
if let profile = entry as? ProviderConnectionProfile {
|
if let profile = entry as? ProviderConnectionProfile {
|
||||||
|
|
Loading…
Reference in New Issue