diff --git a/passKit/Helpers/Utils.swift b/passKit/Helpers/Utils.swift index 31d1b52..715cf41 100644 --- a/passKit/Helpers/Utils.swift +++ b/passKit/Helpers/Utils.swift @@ -11,20 +11,6 @@ import SwiftyUserDefaults import KeychainAccess 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? { let keychain = Keychain(service: Globals.bundleIdentifier, accessGroup: Globals.groupIdentifier) do { diff --git a/passKit/Models/PasswordStore.swift b/passKit/Models/PasswordStore.swift index c1c9bf9..26d5a68 100644 --- a/passKit/Models/PasswordStore.swift +++ b/passKit/Models/PasswordStore.swift @@ -302,17 +302,14 @@ public class PasswordStore { requestGitPassword: @escaping (GitCredential.Credential, String?) -> String?, transferProgressBlock: @escaping (UnsafePointer, UnsafeMutablePointer) -> Void, checkoutProgressBlock: @escaping (String?, UInt, UInt) -> Void) throws { - Utils.removeFileIfExists(at: storeURL) - Utils.removeFileIfExists(at: tempStoreURL) + try? fm.removeItem(at: storeURL) + try? fm.removeItem(at: tempStoreURL) self.gitPassword = nil self.gitSSHPrivateKeyPassphrase = nil do { let credentialProvider = try credential.credentialProvider(requestGitPassword: requestGitPassword) let options = [GTRepositoryCloneOptionsCredentialProvider: credentialProvider] 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) storeRepository = try GTRepository(url: storeURL) } catch { @@ -755,12 +752,12 @@ public class PasswordStore { public func erase() { publicKey = nil privateKey = nil - Utils.removeFileIfExists(at: storeURL) - Utils.removeFileIfExists(at: tempStoreURL) + try? fm.removeItem(at: storeURL) + try? fm.removeItem(at: tempStoreURL) - Utils.removeFileIfExists(atPath: Globals.pgpPublicKeyPath) - Utils.removeFileIfExists(atPath: Globals.pgpPrivateKeyPath) - Utils.removeFileIfExists(atPath: Globals.gitSSHPrivateKeyPath) + try? fm.removeItem(atPath: Globals.pgpPublicKeyPath) + try? fm.removeItem(atPath: Globals.pgpPrivateKeyPath) + try? fm.removeItem(atPath: Globals.gitSSHPrivateKeyPath) Utils.removeAllKeychain() @@ -850,8 +847,8 @@ public class PasswordStore { } public func removePGPKeys() { - Utils.removeFileIfExists(atPath: Globals.pgpPublicKeyPath) - Utils.removeFileIfExists(atPath: Globals.pgpPrivateKeyPath) + try? fm.removeItem(atPath: Globals.pgpPublicKeyPath) + try? fm.removeItem(atPath: Globals.pgpPrivateKeyPath) SharedDefaults.remove(.pgpKeySource) SharedDefaults.remove(.pgpPublicKeyArmor) SharedDefaults.remove(.pgpPrivateKeyArmor) @@ -864,7 +861,7 @@ public class PasswordStore { } public func removeGitSSHKeys() { - Utils.removeFileIfExists(atPath: Globals.gitSSHPrivateKeyPath) + try? fm.removeItem(atPath: Globals.gitSSHPrivateKeyPath) Defaults.remove(.gitSSHPrivateKeyArmor) Defaults.remove(.gitSSHPrivateKeyURL) self.gitSSHPrivateKeyPassphrase = nil