Fix #332: The synced status is now saved in DB
This commit is contained in:
parent
a4b1f87b56
commit
30bb227ae3
1 changed files with 23 additions and 48 deletions
|
|
@ -289,11 +289,7 @@ public class PasswordStore {
|
||||||
} catch {
|
} catch {
|
||||||
print(error)
|
print(error)
|
||||||
}
|
}
|
||||||
do {
|
self.saveUpdatedContext()
|
||||||
try context.save()
|
|
||||||
} catch {
|
|
||||||
print("ErrorSaving".localize(error))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getRecentCommits(count: Int) throws -> [GTCommit] {
|
public func getRecentCommits(count: Int) throws -> [GTCommit] {
|
||||||
|
|
@ -351,15 +347,11 @@ public class PasswordStore {
|
||||||
|
|
||||||
public func setAllSynced() {
|
public func setAllSynced() {
|
||||||
let passwordEntities = fetchUnsyncedPasswords()
|
let passwordEntities = fetchUnsyncedPasswords()
|
||||||
for passwordEntity in passwordEntities {
|
if passwordEntities.count > 0 {
|
||||||
passwordEntity.synced = true
|
for passwordEntity in passwordEntities {
|
||||||
}
|
passwordEntity.synced = true
|
||||||
do {
|
|
||||||
if context.hasChanges {
|
|
||||||
try context.save()
|
|
||||||
}
|
}
|
||||||
} catch {
|
self.saveUpdatedContext()
|
||||||
fatalError("ErrorSaving".localize(error))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -489,35 +481,26 @@ public class PasswordStore {
|
||||||
for path in paths {
|
for path in paths {
|
||||||
let isDir = !path.hasSuffix(".gpg")
|
let isDir = !path.hasSuffix(".gpg")
|
||||||
if let passwordEntity = getPasswordEntity(by: path, isDir: isDir) {
|
if let passwordEntity = getPasswordEntity(by: path, isDir: isDir) {
|
||||||
parentPasswordEntity = passwordEntity
|
|
||||||
passwordEntity.synced = false
|
passwordEntity.synced = false
|
||||||
|
parentPasswordEntity = passwordEntity
|
||||||
} else {
|
} else {
|
||||||
if !isDir {
|
let passwordEntity = NSEntityDescription.insertNewObject(forEntityName: "PasswordEntity", into: self.context) as! PasswordEntity
|
||||||
return insertPasswordEntity(name: URL(string: path.stringByAddingPercentEncodingForRFC3986()!)!.deletingPathExtension().lastPathComponent, path: path, parent: parentPasswordEntity, synced: false, isDir: false)
|
let pathURL = URL(string: path.stringByAddingPercentEncodingForRFC3986()!)!
|
||||||
|
if isDir {
|
||||||
|
passwordEntity.name = pathURL.lastPathComponent
|
||||||
} else {
|
} else {
|
||||||
parentPasswordEntity = insertPasswordEntity(name: URL(string: path.stringByAddingPercentEncodingForRFC3986()!)!.lastPathComponent, path: path, parent: parentPasswordEntity, synced: false, isDir: true)
|
passwordEntity.name = pathURL.deletingPathExtension().lastPathComponent
|
||||||
}
|
}
|
||||||
|
passwordEntity.path = path
|
||||||
|
passwordEntity.parent = parentPasswordEntity
|
||||||
|
passwordEntity.synced = false
|
||||||
|
passwordEntity.isDir = isDir
|
||||||
|
parentPasswordEntity = passwordEntity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
self.saveUpdatedContext()
|
||||||
|
return parentPasswordEntity
|
||||||
private func insertPasswordEntity(name: String, path: String, parent: PasswordEntity?, synced: Bool = false, isDir: Bool = false) -> PasswordEntity? {
|
|
||||||
var ret: PasswordEntity? = nil
|
|
||||||
if let passwordEntity = NSEntityDescription.insertNewObject(forEntityName: "PasswordEntity", into: self.context) as? PasswordEntity {
|
|
||||||
passwordEntity.name = name
|
|
||||||
passwordEntity.path = path
|
|
||||||
passwordEntity.parent = parent
|
|
||||||
passwordEntity.synced = synced
|
|
||||||
passwordEntity.isDir = isDir
|
|
||||||
do {
|
|
||||||
try self.context.save()
|
|
||||||
ret = passwordEntity
|
|
||||||
} catch {
|
|
||||||
fatalError("FailedToInsertPasswordEntity".localize(error))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func add(password: Password) throws -> PasswordEntity? {
|
public func add(password: Password) throws -> PasswordEntity? {
|
||||||
|
|
@ -577,19 +560,15 @@ public class PasswordStore {
|
||||||
let parent = current!.parent
|
let parent = current!.parent
|
||||||
self.context.delete(current!)
|
self.context.delete(current!)
|
||||||
current = parent
|
current = parent
|
||||||
do {
|
|
||||||
try self.context.save()
|
|
||||||
} catch {
|
|
||||||
fatalError("FailedToDeletePasswordEntity".localize(error))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
self.saveUpdatedContext()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func saveUpdated(passwordEntity: PasswordEntity) {
|
public func saveUpdatedContext() {
|
||||||
do {
|
do {
|
||||||
try context.save()
|
try context.save()
|
||||||
} catch {
|
} catch {
|
||||||
fatalError("FailedToSavePasswordEntity".localize(error))
|
fatalError("FailureToSaveContext".localize(error))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -617,11 +596,7 @@ public class PasswordStore {
|
||||||
do {
|
do {
|
||||||
try privateMOC.save()
|
try privateMOC.save()
|
||||||
self.context.performAndWait {
|
self.context.performAndWait {
|
||||||
do {
|
self.saveUpdatedContext()
|
||||||
try self.context.save()
|
|
||||||
} catch {
|
|
||||||
fatalError("FailureToSaveContext".localize(error))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
fatalError("FailureToSaveContext".localize(error))
|
fatalError("FailureToSaveContext".localize(error))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue