Delete the removeFileIfExists funtion
I have no idea why I did write this helper function at the begining.
This commit is contained in:
parent
dfc13a37d3
commit
653ce515ab
2 changed files with 10 additions and 27 deletions
|
|
@ -11,20 +11,6 @@ import SwiftyUserDefaults
|
||||||
import KeychainAccess
|
import KeychainAccess
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
public static func removeFileIfExists(atPath path: String) {
|
|
||||||
let fm = FileManager.default
|
|
||||||
do {
|
|
||||||
if fm.fileExists(atPath: path) {
|
|
||||||
try fm.removeItem(atPath: path)
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
print(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static func removeFileIfExists(at url: URL) {
|
|
||||||
removeFileIfExists(atPath: url.path)
|
|
||||||
}
|
|
||||||
|
|
||||||
public static func getPasswordFromKeychain(name: String) -> String? {
|
public static func getPasswordFromKeychain(name: String) -> String? {
|
||||||
let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
|
let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier)
|
||||||
do {
|
do {
|
||||||
|
|
|
||||||
|
|
@ -302,17 +302,14 @@ public class PasswordStore {
|
||||||
requestGitPassword: @escaping (GitCredential.Credential, String?) -> String?,
|
requestGitPassword: @escaping (GitCredential.Credential, String?) -> String?,
|
||||||
transferProgressBlock: @escaping (UnsafePointer<git_transfer_progress>, UnsafeMutablePointer<ObjCBool>) -> Void,
|
transferProgressBlock: @escaping (UnsafePointer<git_transfer_progress>, UnsafeMutablePointer<ObjCBool>) -> Void,
|
||||||
checkoutProgressBlock: @escaping (String?, UInt, UInt) -> Void) throws {
|
checkoutProgressBlock: @escaping (String?, UInt, UInt) -> Void) throws {
|
||||||
Utils.removeFileIfExists(at: storeURL)
|
try? fm.removeItem(at: storeURL)
|
||||||
Utils.removeFileIfExists(at: tempStoreURL)
|
try? fm.removeItem(at: tempStoreURL)
|
||||||
self.gitPassword = nil
|
self.gitPassword = nil
|
||||||
self.gitSSHPrivateKeyPassphrase = nil
|
self.gitSSHPrivateKeyPassphrase = nil
|
||||||
do {
|
do {
|
||||||
let credentialProvider = try credential.credentialProvider(requestGitPassword: requestGitPassword)
|
let credentialProvider = try credential.credentialProvider(requestGitPassword: requestGitPassword)
|
||||||
let options = [GTRepositoryCloneOptionsCredentialProvider: credentialProvider]
|
let options = [GTRepositoryCloneOptionsCredentialProvider: credentialProvider]
|
||||||
storeRepository = try GTRepository.clone(from: remoteRepoURL, toWorkingDirectory: tempStoreURL, options: options, transferProgressBlock:transferProgressBlock)
|
storeRepository = try GTRepository.clone(from: remoteRepoURL, toWorkingDirectory: tempStoreURL, options: options, transferProgressBlock:transferProgressBlock)
|
||||||
if fm.fileExists(atPath: storeURL.path) {
|
|
||||||
try fm.removeItem(at: storeURL)
|
|
||||||
}
|
|
||||||
try fm.moveItem(at: tempStoreURL, to: storeURL)
|
try fm.moveItem(at: tempStoreURL, to: storeURL)
|
||||||
storeRepository = try GTRepository(url: storeURL)
|
storeRepository = try GTRepository(url: storeURL)
|
||||||
} catch {
|
} catch {
|
||||||
|
|
@ -755,12 +752,12 @@ public class PasswordStore {
|
||||||
public func erase() {
|
public func erase() {
|
||||||
publicKey = nil
|
publicKey = nil
|
||||||
privateKey = nil
|
privateKey = nil
|
||||||
Utils.removeFileIfExists(at: storeURL)
|
try? fm.removeItem(at: storeURL)
|
||||||
Utils.removeFileIfExists(at: tempStoreURL)
|
try? fm.removeItem(at: tempStoreURL)
|
||||||
|
|
||||||
Utils.removeFileIfExists(atPath: Globals.pgpPublicKeyPath)
|
try? fm.removeItem(atPath: Globals.pgpPublicKeyPath)
|
||||||
Utils.removeFileIfExists(atPath: Globals.pgpPrivateKeyPath)
|
try? fm.removeItem(atPath: Globals.pgpPrivateKeyPath)
|
||||||
Utils.removeFileIfExists(atPath: Globals.gitSSHPrivateKeyPath)
|
try? fm.removeItem(atPath: Globals.gitSSHPrivateKeyPath)
|
||||||
|
|
||||||
Utils.removeAllKeychain()
|
Utils.removeAllKeychain()
|
||||||
|
|
||||||
|
|
@ -850,8 +847,8 @@ public class PasswordStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
public func removePGPKeys() {
|
public func removePGPKeys() {
|
||||||
Utils.removeFileIfExists(atPath: Globals.pgpPublicKeyPath)
|
try? fm.removeItem(atPath: Globals.pgpPublicKeyPath)
|
||||||
Utils.removeFileIfExists(atPath: Globals.pgpPrivateKeyPath)
|
try? fm.removeItem(atPath: Globals.pgpPrivateKeyPath)
|
||||||
SharedDefaults.remove(.pgpKeySource)
|
SharedDefaults.remove(.pgpKeySource)
|
||||||
SharedDefaults.remove(.pgpPublicKeyArmor)
|
SharedDefaults.remove(.pgpPublicKeyArmor)
|
||||||
SharedDefaults.remove(.pgpPrivateKeyArmor)
|
SharedDefaults.remove(.pgpPrivateKeyArmor)
|
||||||
|
|
@ -864,7 +861,7 @@ public class PasswordStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
public func removeGitSSHKeys() {
|
public func removeGitSSHKeys() {
|
||||||
Utils.removeFileIfExists(atPath: Globals.gitSSHPrivateKeyPath)
|
try? fm.removeItem(atPath: Globals.gitSSHPrivateKeyPath)
|
||||||
Defaults.remove(.gitSSHPrivateKeyArmor)
|
Defaults.remove(.gitSSHPrivateKeyArmor)
|
||||||
Defaults.remove(.gitSSHPrivateKeyURL)
|
Defaults.remove(.gitSSHPrivateKeyURL)
|
||||||
self.gitSSHPrivateKeyPassphrase = nil
|
self.gitSSHPrivateKeyPassphrase = nil
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue