Clean up very old migration codes
This commit is contained in:
parent
765b487ffa
commit
1ec26a0eea
2 changed files with 2 additions and 55 deletions
|
|
@ -10,16 +10,6 @@ import Foundation
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
public class Globals {
|
public class Globals {
|
||||||
|
|
||||||
// Legacy paths (not shared)
|
|
||||||
public static let documentPathLegacy = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0];
|
|
||||||
public static let libraryPathLegacy = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)[0];
|
|
||||||
public static let pgpPublicKeyPathLegacy = "\(documentPathLegacy)/gpg_key.pub"
|
|
||||||
public static let pgpPrivateKeyPathLegacy = "\(documentPathLegacy)/gpg_key"
|
|
||||||
public static let gitSSHPrivateKeyPathLegacy = "\(documentPathLegacy)/ssh_key"
|
|
||||||
public static let gitSSHPrivateKeyURLLegacy = URL(fileURLWithPath: gitSSHPrivateKeyPathLegacy)
|
|
||||||
public static let repositoryPathLegacy = "\(libraryPathLegacy)/password-store"
|
|
||||||
|
|
||||||
public static let bundleIdentifier = "me.mssun.passforios"
|
public static let bundleIdentifier = "me.mssun.passforios"
|
||||||
public static let groupIdentifier = "group." + bundleIdentifier
|
public static let groupIdentifier = "group." + bundleIdentifier
|
||||||
public static let passKitBundleIdentifier = bundleIdentifier + ".passKit"
|
public static let passKitBundleIdentifier = bundleIdentifier + ".passKit"
|
||||||
|
|
|
||||||
|
|
@ -106,9 +106,7 @@ public class PasswordStore {
|
||||||
private init() {
|
private init() {
|
||||||
self.pgpAgent = PGPAgent()
|
self.pgpAgent = PGPAgent()
|
||||||
|
|
||||||
// File migration to group
|
// Migration
|
||||||
migrateIfNeeded()
|
|
||||||
backwardCompatibility()
|
|
||||||
importExistingKeysIntoKeychain()
|
importExistingKeysIntoKeychain()
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
@ -120,50 +118,9 @@ public class PasswordStore {
|
||||||
print(error)
|
print(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func migrateIfNeeded() {
|
|
||||||
// migrate happens only if the repository was cloned and pgp keys were set up using earlier versions
|
|
||||||
let needMigration = !pgpKeyExists() && !fm.fileExists(atPath: Globals.gitSSHPrivateKeyPath) && !fm.fileExists(atPath: Globals.repositoryPath) && fm.fileExists(atPath: Globals.repositoryPathLegacy)
|
|
||||||
guard needMigration == true else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
|
||||||
// migrate Defaults
|
|
||||||
let userDefaults = UserDefaults()
|
|
||||||
for key in Defaults.dictionaryRepresentation().keys {
|
|
||||||
if SharedDefaults.value(forKey: key) == nil {
|
|
||||||
SharedDefaults.setValue(userDefaults.value(forKey: key), forKey: key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// migrate files
|
|
||||||
try fm.createDirectory(atPath: Globals.documentPath, withIntermediateDirectories: true, attributes: nil)
|
|
||||||
try fm.createDirectory(atPath: Globals.libraryPath, withIntermediateDirectories: true, attributes: nil)
|
|
||||||
if fm.fileExists(atPath: Globals.pgpPublicKeyPathLegacy) {
|
|
||||||
try fm.moveItem(atPath: Globals.pgpPublicKeyPathLegacy, toPath: Globals.pgpPublicKeyPath)
|
|
||||||
}
|
|
||||||
if fm.fileExists(atPath: Globals.pgpPrivateKeyPathLegacy) {
|
|
||||||
try fm.moveItem(atPath: Globals.pgpPrivateKeyPathLegacy, toPath: Globals.pgpPrivateKeyPath)
|
|
||||||
}
|
|
||||||
if fm.fileExists(atPath: Globals.gitSSHPrivateKeyPathLegacy) {
|
|
||||||
try fm.moveItem(atPath: Globals.gitSSHPrivateKeyPathLegacy, toPath: Globals.gitSSHPrivateKeyPath)
|
|
||||||
}
|
|
||||||
try fm.moveItem(atPath: Globals.repositoryPathLegacy, toPath: Globals.repositoryPath)
|
|
||||||
} catch {
|
|
||||||
print("MigrationError".localize(error))
|
|
||||||
}
|
|
||||||
updatePasswordEntityCoreData()
|
|
||||||
}
|
|
||||||
|
|
||||||
private func backwardCompatibility() {
|
|
||||||
// For the newly-introduced isRememberGitCredentialPassphraseOn (20171008)
|
|
||||||
if (self.gitPassword != nil || self.gitSSHPrivateKeyPassphrase != nil) && SharedDefaults[.isRememberGitCredentialPassphraseOn] == false {
|
|
||||||
SharedDefaults[.isRememberGitCredentialPassphraseOn] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func importExistingKeysIntoKeychain() {
|
private func importExistingKeysIntoKeychain() {
|
||||||
|
// App Store update: v0.5.1 -> v0.6.0
|
||||||
try? KeyFileManager(keyType: PgpKey.PUBLIC, keyPath: Globals.pgpPublicKeyPath).importKeyAndDeleteFile()
|
try? KeyFileManager(keyType: PgpKey.PUBLIC, keyPath: Globals.pgpPublicKeyPath).importKeyAndDeleteFile()
|
||||||
try? KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: Globals.pgpPrivateKeyPath).importKeyAndDeleteFile()
|
try? KeyFileManager(keyType: PgpKey.PRIVATE, keyPath: Globals.pgpPrivateKeyPath).importKeyAndDeleteFile()
|
||||||
try? KeyFileManager(keyType: SshKey.PRIVATE, keyPath: Globals.gitSSHPrivateKeyPath).importKeyAndDeleteFile()
|
try? KeyFileManager(keyType: SshKey.PRIVATE, keyPath: Globals.gitSSHPrivateKeyPath).importKeyAndDeleteFile()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue