mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Fix delete methods
This commit is contained in:
@@ -40,7 +40,7 @@ class DeleteNodesRunnable(context: Context,
|
||||
|
||||
foreachNode@ for(nodeToDelete in mNodesToDelete) {
|
||||
mOldParent = nodeToDelete.parent
|
||||
mOldParent?.touch(modified = false, touchParents = true)
|
||||
nodeToDelete.touch(modified = true, touchParents = true)
|
||||
|
||||
when (nodeToDelete.type) {
|
||||
Type.GROUP -> {
|
||||
@@ -50,9 +50,9 @@ class DeleteNodesRunnable(context: Context,
|
||||
// Remove Node from parent
|
||||
mCanRecycle = database.canRecycle(groupToDelete)
|
||||
if (mCanRecycle) {
|
||||
groupToDelete.touch(modified = false, touchParents = true)
|
||||
database.recycle(groupToDelete, context.resources)
|
||||
groupToDelete.setPreviousParentGroup(mOldParent)
|
||||
groupToDelete.touch(modified = true, touchParents = true)
|
||||
} else {
|
||||
database.deleteGroup(groupToDelete)
|
||||
}
|
||||
@@ -64,9 +64,9 @@ class DeleteNodesRunnable(context: Context,
|
||||
// Remove Node from parent
|
||||
mCanRecycle = database.canRecycle(entryToDelete)
|
||||
if (mCanRecycle) {
|
||||
entryToDelete.touch(modified = false, touchParents = true)
|
||||
database.recycle(entryToDelete, context.resources)
|
||||
entryToDelete.setPreviousParentGroup(mOldParent)
|
||||
entryToDelete.touch(modified = true, touchParents = true)
|
||||
} else {
|
||||
database.deleteEntry(entryToDelete)
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ class MoveNodesRunnable constructor(
|
||||
foreachNode@ for(nodeToMove in mNodesToMove) {
|
||||
// Move node in new parent
|
||||
mOldParent = nodeToMove.parent
|
||||
nodeToMove.touch(modified = true, touchParents = true)
|
||||
|
||||
when (nodeToMove.type) {
|
||||
Type.GROUP -> {
|
||||
@@ -52,9 +53,9 @@ class MoveNodesRunnable constructor(
|
||||
// and if not in the current group
|
||||
&& groupToMove != mNewParent
|
||||
&& !mNewParent.isContainedIn(groupToMove)) {
|
||||
groupToMove.touch(modified = true, touchParents = true)
|
||||
database.moveGroupTo(groupToMove, mNewParent)
|
||||
groupToMove.setPreviousParentGroup(mOldParent)
|
||||
groupToMove.touch(modified = true, touchParents = true)
|
||||
} else {
|
||||
// Only finish thread
|
||||
setError(MoveGroupDatabaseException())
|
||||
@@ -67,9 +68,9 @@ class MoveNodesRunnable constructor(
|
||||
if (mOldParent != mNewParent
|
||||
// and root can contains entry
|
||||
&& (mNewParent != database.rootGroup || database.rootCanContainsEntry())) {
|
||||
entryToMove.touch(modified = true, touchParents = true)
|
||||
database.moveEntryTo(entryToMove, mNewParent)
|
||||
entryToMove.setPreviousParentGroup(mOldParent)
|
||||
entryToMove.touch(modified = true, touchParents = true)
|
||||
} else {
|
||||
// Only finish thread
|
||||
setError(MoveEntryDatabaseException())
|
||||
|
||||
@@ -456,8 +456,9 @@ class Database {
|
||||
// Only the kdbx recycle bin can be changed
|
||||
if (group != null) {
|
||||
mDatabaseKDBX?.recycleBinUUID = group.nodeIdKDBX.id
|
||||
mDatabaseKDBX?.recycleBinChanged = DateInstant()
|
||||
} else {
|
||||
mDatabaseKDBX?.removeTemplatesGroup()
|
||||
mDatabaseKDBX?.removeRecycleBin()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,7 +490,7 @@ class Database {
|
||||
if (group != null) {
|
||||
mDatabaseKDBX?.entryTemplatesGroup = group.nodeIdKDBX.id
|
||||
} else {
|
||||
mDatabaseKDBX?.entryTemplatesGroup
|
||||
mDatabaseKDBX?.removeTemplatesGroup()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1052,24 +1053,6 @@ class Database {
|
||||
})
|
||||
}
|
||||
|
||||
fun undoDeleteEntry(entry: Entry, parent: Group) {
|
||||
entry.entryKDB?.let {
|
||||
mDatabaseKDB?.undoDeleteEntryFrom(it, parent.groupKDB)
|
||||
}
|
||||
entry.entryKDBX?.let {
|
||||
mDatabaseKDBX?.undoDeleteEntryFrom(it, parent.groupKDBX)
|
||||
}
|
||||
}
|
||||
|
||||
fun undoDeleteGroup(group: Group, parent: Group) {
|
||||
group.groupKDB?.let {
|
||||
mDatabaseKDB?.undoDeleteGroupFrom(it, parent.groupKDB)
|
||||
}
|
||||
group.groupKDBX?.let {
|
||||
mDatabaseKDBX?.undoDeleteGroupFrom(it, parent.groupKDBX)
|
||||
}
|
||||
}
|
||||
|
||||
fun ensureRecycleBinExists(resources: Resources) {
|
||||
mDatabaseKDB?.ensureBackupExists()
|
||||
mDatabaseKDBX?.ensureRecycleBinExists(resources)
|
||||
|
||||
@@ -66,6 +66,7 @@ import javax.crypto.Mac
|
||||
import javax.xml.XMLConstants
|
||||
import javax.xml.parsers.DocumentBuilderFactory
|
||||
import javax.xml.parsers.ParserConfigurationException
|
||||
import kotlin.collections.HashSet
|
||||
import kotlin.math.min
|
||||
|
||||
|
||||
@@ -115,7 +116,7 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
|
||||
var lastSelectedGroupUUID = UUID_ZERO
|
||||
var lastTopVisibleGroupUUID = UUID_ZERO
|
||||
var memoryProtection = MemoryProtectionConfig()
|
||||
val deletedObjects = ArrayList<DeletedObject>()
|
||||
val deletedObjects = HashSet<DeletedObject>()
|
||||
val customData = CustomData()
|
||||
|
||||
var localizedAppName = "KeePassDX"
|
||||
@@ -753,14 +754,19 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
|
||||
return false
|
||||
}
|
||||
|
||||
fun getDeletedObjects(): List<DeletedObject> {
|
||||
return deletedObjects
|
||||
fun getDeletedObject(id: UUID): DeletedObject? {
|
||||
return deletedObjects.find { it.uuid == id }
|
||||
}
|
||||
|
||||
fun addDeletedObject(deletedObject: DeletedObject) {
|
||||
this.deletedObjects.add(deletedObject)
|
||||
}
|
||||
|
||||
override fun removeGroupFrom(groupToRemove: GroupKDBX, parent: GroupKDBX?) {
|
||||
super.removeGroupFrom(groupToRemove, parent)
|
||||
addDeletedObject(DeletedObject(groupToRemove.id))
|
||||
}
|
||||
|
||||
override fun addEntryTo(newEntry: EntryKDBX, parent: GroupKDBX?) {
|
||||
super.addEntryTo(newEntry, parent)
|
||||
mFieldReferenceEngine.clear()
|
||||
@@ -773,15 +779,10 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
|
||||
|
||||
override fun removeEntryFrom(entryToRemove: EntryKDBX, parent: GroupKDBX?) {
|
||||
super.removeEntryFrom(entryToRemove, parent)
|
||||
deletedObjects.add(DeletedObject(entryToRemove.id))
|
||||
addDeletedObject(DeletedObject(entryToRemove.id))
|
||||
mFieldReferenceEngine.clear()
|
||||
}
|
||||
|
||||
override fun undoDeleteEntryFrom(entry: EntryKDBX, origParent: GroupKDBX?) {
|
||||
super.undoDeleteEntryFrom(entry, origParent)
|
||||
deletedObjects.remove(DeletedObject(entry.id))
|
||||
}
|
||||
|
||||
fun containsPublicCustomData(): Boolean {
|
||||
return publicCustomData.size() > 0
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ abstract class DatabaseVersioned<
|
||||
}
|
||||
}
|
||||
|
||||
fun removeGroupFrom(groupToRemove: Group, parent: Group?) {
|
||||
open fun removeGroupFrom(groupToRemove: Group, parent: Group?) {
|
||||
// Remove tree from parent tree
|
||||
parent?.removeChildGroup(groupToRemove)
|
||||
removeGroupIndex(groupToRemove)
|
||||
@@ -354,15 +354,6 @@ abstract class DatabaseVersioned<
|
||||
removeEntryIndex(entryToRemove)
|
||||
}
|
||||
|
||||
// TODO Delete group
|
||||
fun undoDeleteGroupFrom(group: Group, origParent: Group?) {
|
||||
addGroupTo(group, origParent)
|
||||
}
|
||||
|
||||
open fun undoDeleteEntryFrom(entry: Entry, origParent: Group?) {
|
||||
addEntryTo(entry, origParent)
|
||||
}
|
||||
|
||||
abstract fun isInRecycleBin(group: Group): Boolean
|
||||
|
||||
fun isGroupSearchable(group: Group?, omitBackup: Boolean): Boolean {
|
||||
|
||||
@@ -618,7 +618,7 @@ class DatabaseOutputKDBX(private val mDatabaseKDBX: DatabaseKDBX,
|
||||
}
|
||||
|
||||
@Throws(IllegalArgumentException::class, IllegalStateException::class, IOException::class)
|
||||
private fun writeDeletedObjects(value: List<DeletedObject>) {
|
||||
private fun writeDeletedObjects(value: Collection<DeletedObject>) {
|
||||
xml.startTag(null, DatabaseKDBXXML.ElemDeletedObjects)
|
||||
|
||||
for (pdo in value) {
|
||||
|
||||
Reference in New Issue
Block a user