From 98cc71bf3022b0c1c9f90cd364e5eb032f34c053 Mon Sep 17 00:00:00 2001 From: Bob Sun Date: Wed, 26 Apr 2017 23:02:05 -0700 Subject: [PATCH] Fix gitRm issue --- pass/Models/PasswordStore.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pass/Models/PasswordStore.swift b/pass/Models/PasswordStore.swift index 4b7fa49..d9f4897 100644 --- a/pass/Models/PasswordStore.swift +++ b/pass/Models/PasswordStore.swift @@ -288,10 +288,10 @@ class PasswordStore { return true } - func getPasswordEntity(by path: String) -> PasswordEntity? { + func getPasswordEntity(by path: String, isDir: Bool) -> PasswordEntity? { let passwordEntityFetchRequest = NSFetchRequest(entityName: "PasswordEntity") 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 } catch { fatalError("Failed to fetch password entities: \(error)") @@ -518,6 +518,9 @@ class PasswordStore { private func gitRm(path: String) throws { 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().write() } @@ -604,10 +607,12 @@ class PasswordStore { paths.reverse() var parentPasswordEntity: PasswordEntity? = nil 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 } else { - if path.hasSuffix(".gpg") { + if !isDir { return insertPasswordEntity(name: URL(string: path.stringByAddingPercentEncodingForRFC3986()!)!.deletingPathExtension().lastPathComponent, path: path, parent: parentPasswordEntity, synced: false, isDir: false) } else { parentPasswordEntity = insertPasswordEntity(name: URL(string: path.stringByAddingPercentEncodingForRFC3986()!)!.lastPathComponent, path: path, parent: parentPasswordEntity, synced: false, isDir: true)