Locate profiles via relative URLs

Avoid absolute URLs, profiles directory is always relative to
documents. Assume profiles to be based in the documents root
unless directory is != nil.

Given that, starting from iOS 8, the documents location can change
from time to time, could this fix #19?
This commit is contained in:
Davide De Rosa 2018-11-01 13:25:33 +01:00
parent 2197c96bd9
commit 36995e089b
3 changed files with 10 additions and 13 deletions

View File

@ -59,7 +59,7 @@ extension ConnectionService {
func pendingConfigurationURLs() -> [URL] {
do {
let list = try FileManager.default.contentsOfDirectory(at: directory, includingPropertiesForKeys: nil, options: [])
let list = try FileManager.default.contentsOfDirectory(at: rootURL, includingPropertiesForKeys: nil, options: [])
return list.filter { $0.pathExtension == "ovpn" }
} catch let e {
log.error("Could not list imported configurations: \(e)")

View File

@ -83,14 +83,18 @@ class ConnectionService: Codable {
}
}
lazy var directory = FileManager.default.userURL(for: .documentDirectory, appending: nil)
var directory: String? = nil
var rootURL: URL {
return FileManager.default.userURL(for: .documentDirectory, appending: directory)
}
private var providersURL: URL {
return directory.appendingPathComponent(AppConstants.Store.providersDirectory)
return rootURL.appendingPathComponent(AppConstants.Store.providersDirectory)
}
private var hostsURL: URL {
return directory.appendingPathComponent(AppConstants.Store.hostsDirectory)
return rootURL.appendingPathComponent(AppConstants.Store.hostsDirectory)
}
private var build: Int

View File

@ -35,12 +35,10 @@ class TransientStore {
static let shared = TransientStore()
private let rootURL: URL
private let serviceURL: URL
let service: ConnectionService
private let serviceURL = FileManager.default.userURL(for: .documentDirectory, appending: AppConstants.Store.serviceFilename)
var didHandleSubreddit: Bool {
get {
return UserDefaults.standard.bool(forKey: Keys.didHandleSubreddit)
@ -51,9 +49,6 @@ class TransientStore {
}
private init() {
rootURL = FileManager.default.userURL(for: .documentDirectory, appending: nil)
serviceURL = rootURL.appendingPathComponent(AppConstants.Store.serviceFilename)
let cfg = AppConstants.VPN.baseConfiguration()
do {
ConnectionService.migrateJSON(at: serviceURL, to: serviceURL)
@ -64,7 +59,6 @@ class TransientStore {
log.verbose(content)
}
service = try JSONDecoder().decode(ConnectionService.self, from: data)
service.directory = rootURL
service.baseConfiguration = cfg
service.loadProfiles()
} catch let e {
@ -73,7 +67,6 @@ class TransientStore {
withAppGroup: GroupConstants.App.appGroup,
baseConfiguration: cfg
)
service.directory = rootURL
// // hardcoded loading
// _ = service.addProfile(ProviderConnectionProfile(name: .pia), credentials: nil)