mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Better node error implementation
This commit is contained in:
@@ -24,6 +24,7 @@ import android.util.Log
|
||||
import com.kunzisoft.keepass.database.element.*
|
||||
import com.kunzisoft.keepass.database.exception.CopyDatabaseEntryException
|
||||
import com.kunzisoft.keepass.database.exception.CopyDatabaseGroupException
|
||||
import com.kunzisoft.keepass.database.exception.LoadDatabaseException
|
||||
|
||||
class CopyNodesRunnable constructor(
|
||||
context: Context,
|
||||
@@ -38,33 +39,42 @@ class CopyNodesRunnable constructor(
|
||||
|
||||
override fun nodeAction() {
|
||||
|
||||
mNodesToCopy.forEach { currentNode ->
|
||||
var error: LoadDatabaseException? = null
|
||||
foreachNode@ for(currentNode in mNodesToCopy) {
|
||||
|
||||
when (currentNode.type) {
|
||||
Type.GROUP -> {
|
||||
Log.e(TAG, "Copy not allowed for group")// Only finish thread
|
||||
throwErrorAndFinish(CopyDatabaseGroupException())
|
||||
error = CopyDatabaseGroupException()
|
||||
break@foreachNode
|
||||
}
|
||||
Type.ENTRY -> {
|
||||
// Root can contains entry
|
||||
if (mNewParent != database.rootGroup || database.rootCanContainsEntry()) {
|
||||
// Update entry with new values
|
||||
mNewParent.touch(modified = false, touchParents = true)
|
||||
database.copyEntryTo(currentNode as EntryVersioned, mNewParent)?.let { entryCopied ->
|
||||
|
||||
val entryCopied = database.copyEntryTo(currentNode as EntryVersioned, mNewParent)
|
||||
if (entryCopied != null) {
|
||||
entryCopied.touch(modified = true, touchParents = true)
|
||||
mEntriesCopied.add(entryCopied)
|
||||
} ?: run {
|
||||
} else {
|
||||
Log.e(TAG, "Unable to create a copy of the entry")
|
||||
throwErrorAndFinish(CopyDatabaseEntryException())
|
||||
error = CopyDatabaseEntryException()
|
||||
break@foreachNode
|
||||
}
|
||||
} else {
|
||||
// Only finish thread
|
||||
throwErrorAndFinish(CopyDatabaseEntryException())
|
||||
error = CopyDatabaseEntryException()
|
||||
break@foreachNode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
saveDatabaseAndFinish()
|
||||
if (error != null)
|
||||
throwErrorAndFinish(error)
|
||||
else
|
||||
saveDatabaseAndFinish()
|
||||
}
|
||||
|
||||
override fun nodeFinish(result: Result): ActionNodeValues {
|
||||
|
||||
@@ -36,7 +36,7 @@ class DeleteNodesRunnable(context: Context,
|
||||
|
||||
override fun nodeAction() {
|
||||
|
||||
mNodesToDelete.forEach { currentNode ->
|
||||
foreachNode@ for(currentNode in mNodesToDelete) {
|
||||
mParent = currentNode.parent
|
||||
mParent?.touch(modified = false, touchParents = true)
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ package com.kunzisoft.keepass.database.action.node
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.kunzisoft.keepass.database.element.*
|
||||
import com.kunzisoft.keepass.database.exception.LoadDatabaseException
|
||||
import com.kunzisoft.keepass.database.exception.MoveDatabaseEntryException
|
||||
import com.kunzisoft.keepass.database.exception.MoveDatabaseGroupException
|
||||
|
||||
@@ -38,10 +39,10 @@ class MoveNodesRunnable constructor(
|
||||
|
||||
override fun nodeAction() {
|
||||
|
||||
mNodesToMove.forEach { nodeToMove ->
|
||||
var error: LoadDatabaseException? = null
|
||||
foreachNode@ for(nodeToMove in mNodesToMove) {
|
||||
// Move node in new parent
|
||||
mOldParent = nodeToMove.parent
|
||||
nodeToMove.touch(modified = true, touchParents = true)
|
||||
|
||||
when (nodeToMove.type) {
|
||||
Type.GROUP -> {
|
||||
@@ -49,10 +50,12 @@ class MoveNodesRunnable constructor(
|
||||
// Move group in new parent if not in the current group
|
||||
if (groupToMove != mNewParent
|
||||
&& !mNewParent.isContainedIn(groupToMove)) {
|
||||
nodeToMove.touch(modified = true, touchParents = true)
|
||||
database.moveGroupTo(groupToMove, mNewParent)
|
||||
} else {
|
||||
// Only finish thread
|
||||
throwErrorAndFinish(MoveDatabaseGroupException())
|
||||
error = MoveDatabaseGroupException()
|
||||
break@foreachNode
|
||||
}
|
||||
}
|
||||
Type.ENTRY -> {
|
||||
@@ -61,15 +64,20 @@ class MoveNodesRunnable constructor(
|
||||
if (mOldParent != mNewParent
|
||||
// and root can contains entry
|
||||
&& (mNewParent != database.rootGroup || database.rootCanContainsEntry())) {
|
||||
nodeToMove.touch(modified = true, touchParents = true)
|
||||
database.moveEntryTo(entryToMove, mNewParent)
|
||||
} else {
|
||||
// Only finish thread
|
||||
throwErrorAndFinish(MoveDatabaseEntryException())
|
||||
error = MoveDatabaseEntryException()
|
||||
break@foreachNode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
saveDatabaseAndFinish()
|
||||
if (error != null)
|
||||
throwErrorAndFinish(error)
|
||||
else
|
||||
saveDatabaseAndFinish()
|
||||
}
|
||||
|
||||
override fun nodeFinish(result: Result): ActionNodeValues {
|
||||
|
||||
Reference in New Issue
Block a user