Fix actions duplicate entries

This commit is contained in:
J-Jamet
2019-08-19 00:07:14 +02:00
parent c6f259d18f
commit 75b028daf3
2 changed files with 20 additions and 9 deletions

View File

@@ -19,6 +19,7 @@
*/ */
package com.kunzisoft.keepass.database.element package com.kunzisoft.keepass.database.element
import android.util.Log
import com.kunzisoft.keepass.database.exception.InvalidKeyFileException import com.kunzisoft.keepass.database.exception.InvalidKeyFileException
import com.kunzisoft.keepass.database.exception.KeyFileEmptyException import com.kunzisoft.keepass.database.exception.KeyFileEmptyException
import com.kunzisoft.keepass.utils.MemUtil import com.kunzisoft.keepass.utils.MemUtil
@@ -234,8 +235,11 @@ abstract class PwDatabase<Group : PwGroup<*, Group, Entry>, Entry : PwEntry<Grou
fun addGroupIndex(group: Group) { fun addGroupIndex(group: Group) {
val groupId = group.nodeId val groupId = group.nodeId
if (!groupIndexes.containsKey(groupId)) if (groupIndexes.containsKey(groupId)) {
Log.e(TAG, "Error, a group with the same UUID $groupId already exists")
} else {
this.groupIndexes[groupId] = group this.groupIndexes[groupId] = group
}
} }
fun removeGroupIndex(group: Group) { fun removeGroupIndex(group: Group) {
@@ -266,8 +270,11 @@ abstract class PwDatabase<Group : PwGroup<*, Group, Entry>, Entry : PwEntry<Grou
fun addEntryIndex(entry: Entry) { fun addEntryIndex(entry: Entry) {
val entryId = entry.nodeId val entryId = entry.nodeId
if (!entryIndexes.containsKey(entryId)) if (entryIndexes.containsKey(entryId)) {
Log.e(TAG, "Error, a group with the same UUID $entryId already exists, change the UUID")
} else {
this.entryIndexes[entryId] = entry this.entryIndexes[entryId] = entry
}
} }
fun removeEntryIndex(entry: Entry) { fun removeEntryIndex(entry: Entry) {
@@ -310,7 +317,7 @@ abstract class PwDatabase<Group : PwGroup<*, Group, Entry>, Entry : PwEntry<Grou
} }
open fun removeEntryFrom(entryToRemove: Entry, parent: Group?) { open fun removeEntryFrom(entryToRemove: Entry, parent: Group?) {
// Remove entry for parent // Remove entry from parent
parent?.removeChildEntry(entryToRemove) parent?.removeChildEntry(entryToRemove)
removeEntryIndex(entryToRemove) removeEntryIndex(entryToRemove)
} }
@@ -336,6 +343,8 @@ abstract class PwDatabase<Group : PwGroup<*, Group, Entry>, Entry : PwEntry<Grou
companion object { companion object {
private const val TAG = "PwDatabase"
val UUID_ZERO = UUID(0, 0) val UUID_ZERO = UUID(0, 0)
fun hexStringToByteArray(s: String): ByteArray { fun hexStringToByteArray(s: String): ByteArray {

View File

@@ -12,9 +12,9 @@ abstract class PwGroup
private var titleGroup = "" private var titleGroup = ""
@Transient @Transient
private val childGroups = LinkedHashSet<Group>() private val childGroups = ArrayList<Group>()
@Transient @Transient
private val childEntries = LinkedHashSet<Entry>() private val childEntries = ArrayList<Entry>()
constructor() : super() constructor() : super()
@@ -39,20 +39,22 @@ abstract class PwGroup
set(value) { titleGroup = value } set(value) { titleGroup = value }
override fun getChildGroups(): MutableList<Group> { override fun getChildGroups(): MutableList<Group> {
return childGroups.toMutableList() return childGroups
} }
override fun getChildEntries(): MutableList<Entry> { override fun getChildEntries(): MutableList<Entry> {
return childEntries.toMutableList() return childEntries
} }
override fun addChildGroup(group: Group) { override fun addChildGroup(group: Group) {
// TODO duplicate UUID if (childGroups.contains(group))
removeChildGroup(group)
this.childGroups.add(group) this.childGroups.add(group)
} }
override fun addChildEntry(entry: Entry) { override fun addChildEntry(entry: Entry) {
// TODO duplicate UUID if (childEntries.contains(entry))
removeChildEntry(entry)
this.childEntries.add(entry) this.childEntries.add(entry)
} }