Fix gitRm issue
This commit is contained in:
parent
b3e7ed25cd
commit
98cc71bf30
1 changed files with 9 additions and 4 deletions
|
|
@ -288,10 +288,10 @@ class PasswordStore {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPasswordEntity(by path: String) -> PasswordEntity? {
|
func getPasswordEntity(by path: String, isDir: Bool) -> PasswordEntity? {
|
||||||
let passwordEntityFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordEntity")
|
let passwordEntityFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "PasswordEntity")
|
||||||
do {
|
do {
|
||||||
passwordEntityFetchRequest.predicate = NSPredicate(format: "path = %@", path)
|
passwordEntityFetchRequest.predicate = NSPredicate(format: "path = %@ and isDir = %@", path, isDir.description)
|
||||||
return try context.fetch(passwordEntityFetchRequest).first as? PasswordEntity
|
return try context.fetch(passwordEntityFetchRequest).first as? PasswordEntity
|
||||||
} catch {
|
} catch {
|
||||||
fatalError("Failed to fetch password entities: \(error)")
|
fatalError("Failed to fetch password entities: \(error)")
|
||||||
|
|
@ -518,6 +518,9 @@ class PasswordStore {
|
||||||
|
|
||||||
private func gitRm(path: String) throws {
|
private func gitRm(path: String) throws {
|
||||||
if let repo = storeRepository {
|
if let repo = storeRepository {
|
||||||
|
if FileManager.default.fileExists(atPath: storeURL.appendingPathComponent(path).path) {
|
||||||
|
try FileManager.default.removeItem(at: storeURL.appendingPathComponent(path))
|
||||||
|
}
|
||||||
try repo.index().removeFile(path)
|
try repo.index().removeFile(path)
|
||||||
try repo.index().write()
|
try repo.index().write()
|
||||||
}
|
}
|
||||||
|
|
@ -604,10 +607,12 @@ class PasswordStore {
|
||||||
paths.reverse()
|
paths.reverse()
|
||||||
var parentPasswordEntity: PasswordEntity? = nil
|
var parentPasswordEntity: PasswordEntity? = nil
|
||||||
for path in paths {
|
for path in paths {
|
||||||
if let passwordEntity = getPasswordEntity(by: path) {
|
let isDir = !path.hasSuffix(".gpg")
|
||||||
|
if let passwordEntity = getPasswordEntity(by: path, isDir: isDir) {
|
||||||
|
print(passwordEntity.path!)
|
||||||
parentPasswordEntity = passwordEntity
|
parentPasswordEntity = passwordEntity
|
||||||
} else {
|
} else {
|
||||||
if path.hasSuffix(".gpg") {
|
if !isDir {
|
||||||
return insertPasswordEntity(name: URL(string: path.stringByAddingPercentEncodingForRFC3986()!)!.deletingPathExtension().lastPathComponent, path: path, parent: parentPasswordEntity, synced: false, isDir: false)
|
return insertPasswordEntity(name: URL(string: path.stringByAddingPercentEncodingForRFC3986()!)!.deletingPathExtension().lastPathComponent, path: path, parent: parentPasswordEntity, synced: false, isDir: false)
|
||||||
} else {
|
} else {
|
||||||
parentPasswordEntity = insertPasswordEntity(name: URL(string: path.stringByAddingPercentEncodingForRFC3986()!)!.lastPathComponent, path: path, parent: parentPasswordEntity, synced: false, isDir: true)
|
parentPasswordEntity = insertPasswordEntity(name: URL(string: path.stringByAddingPercentEncodingForRFC3986()!)!.lastPathComponent, path: path, parent: parentPasswordEntity, synced: false, isDir: true)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue