fix deleting directory
this used to corrupt the local state (password entities remained in DB but files/dirs were removed from git and disk)
This commit is contained in:
parent
12c8c04203
commit
98646242e0
4 changed files with 24 additions and 0 deletions
|
|
@ -73,6 +73,7 @@
|
||||||
"KeyImportError." = "Cannot import the key.";
|
"KeyImportError." = "Cannot import the key.";
|
||||||
"FileNotFoundError." = "File '%@' cannot be read.";
|
"FileNotFoundError." = "File '%@' cannot be read.";
|
||||||
"PasswordDuplicatedError." = "Cannot add the password; password is duplicated.";
|
"PasswordDuplicatedError." = "Cannot add the password; password is duplicated.";
|
||||||
|
"CannotDeleteDirectoryError." = "Cannot delete directories; delete passwords instead.";
|
||||||
"GitResetError." = "Cannot identify the latest synced commit.";
|
"GitResetError." = "Cannot identify the latest synced commit.";
|
||||||
"GitCreateSignatureError." = "Cannot create a valid author/committer signature.";
|
"GitCreateSignatureError." = "Cannot create a valid author/committer signature.";
|
||||||
"GitPushNotSuccessfulError." = "Pushing local changes was not successful. Make sure there are no uncommitted changes on the remote repository.";
|
"GitPushNotSuccessfulError." = "Pushing local changes was not successful. Make sure there are no uncommitted changes on the remote repository.";
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ public enum AppError: Error, Equatable {
|
||||||
case keyImport
|
case keyImport
|
||||||
case readingFile(fileName: String)
|
case readingFile(fileName: String)
|
||||||
case passwordDuplicated
|
case passwordDuplicated
|
||||||
|
case cannotDeleteDirectory
|
||||||
case gitReset
|
case gitReset
|
||||||
case gitCommit
|
case gitCommit
|
||||||
case gitCreateSignature
|
case gitCreateSignature
|
||||||
|
|
|
||||||
|
|
@ -273,6 +273,10 @@ public class PasswordStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
public func delete(passwordEntity: PasswordEntity) throws {
|
public func delete(passwordEntity: PasswordEntity) throws {
|
||||||
|
if passwordEntity.isDir {
|
||||||
|
throw AppError.cannotDeleteDirectory
|
||||||
|
}
|
||||||
|
|
||||||
let deletedFileURL = passwordEntity.fileURL(in: storeURL)
|
let deletedFileURL = passwordEntity.fileURL(in: storeURL)
|
||||||
let deletedFilePath = passwordEntity.path
|
let deletedFilePath = passwordEntity.path
|
||||||
try gitRm(path: passwordEntity.path)
|
try gitRm(path: passwordEntity.path)
|
||||||
|
|
|
||||||
|
|
@ -143,9 +143,27 @@ final class PasswordStoreTest: XCTestCase {
|
||||||
try passwordStore.delete(passwordEntity: entity!)
|
try passwordStore.delete(passwordEntity: entity!)
|
||||||
|
|
||||||
XCTAssertNil(passwordStore.fetchPasswordEntity(with: "personal/github.com.gpg"))
|
XCTAssertNil(passwordStore.fetchPasswordEntity(with: "personal/github.com.gpg"))
|
||||||
|
XCTAssertNil(passwordStore.fetchPasswordEntity(with: "personal"))
|
||||||
|
XCTAssertFalse(FileManager.default.fileExists(atPath: localRepoURL.appendingPathComponent("personal").path))
|
||||||
waitForExpectations(timeout: 1, handler: nil)
|
waitForExpectations(timeout: 1, handler: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testDeleteDirectoryFails() throws {
|
||||||
|
try cloneRepository(.withGPGID)
|
||||||
|
|
||||||
|
expectation(forNotification: .passwordStoreUpdated, object: nil).isInverted = true
|
||||||
|
|
||||||
|
let entity = passwordStore.fetchPasswordEntity(with: "personal")
|
||||||
|
XCTAssertThrowsError(try passwordStore.delete(passwordEntity: entity!)) { error in
|
||||||
|
XCTAssertTrue(error is AppError, "Unexpected error type: \(type(of: error))")
|
||||||
|
XCTAssertEqual(error as? AppError, .cannotDeleteDirectory)
|
||||||
|
}
|
||||||
|
|
||||||
|
XCTAssertNotNil(passwordStore.fetchPasswordEntity(with: "personal/github.com.gpg"))
|
||||||
|
XCTAssertTrue(FileManager.default.fileExists(atPath: localRepoURL.appendingPathComponent("personal/github.com.gpg").path))
|
||||||
|
waitForExpectations(timeout: 0.1, handler: nil)
|
||||||
|
}
|
||||||
|
|
||||||
func testEditPasswordValue() throws {
|
func testEditPasswordValue() throws {
|
||||||
try cloneRepository(.withGPGID)
|
try cloneRepository(.withGPGID)
|
||||||
try importSinglePGPKey()
|
try importSinglePGPKey()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue