First pass to fix attachment deleted in history

This commit is contained in:
J-Jamet
2020-08-28 11:08:30 +02:00
parent 60412cc90b
commit b72d858480
5 changed files with 13 additions and 7 deletions

View File

@@ -325,8 +325,8 @@ class Entry : Node, EntryVersionedInterface<Group> {
entryKDBX?.stopToManageFieldReferences()
}
fun getAttachments(binaryPool: BinaryPool): ArrayList<Attachment> {
val attachments = ArrayList<Attachment>()
fun getAttachments(binaryPool: BinaryPool): Set<Attachment> {
val attachments = HashSet<Attachment>()
entryKDB?.getAttachments()?.let {
attachments.addAll(it)
}

View File

@@ -588,7 +588,7 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
// Remove binaries from the list
rootGroup?.doForEachChild(object : NodeHandler<EntryKDBX>() {
override fun operate(node: EntryKDBX): Boolean {
node.getAttachments(binaryPool).forEach {
node.getAttachments(binaryPool, true).forEach {
binariesToRemove.remove(it.binaryAttachment)
}
return binariesToRemove.isNotEmpty()

View File

@@ -38,6 +38,7 @@ import com.kunzisoft.keepass.utils.ParcelableUtil
import com.kunzisoft.keepass.utils.UnsignedLong
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashSet
import kotlin.collections.LinkedHashMap
class EntryKDBX : EntryVersioned<UUID, UUID, GroupKDBX, EntryKDBX>, NodeKDBXInterface {
@@ -283,13 +284,18 @@ class EntryKDBX : EntryVersioned<UUID, UUID, GroupKDBX, EntryKDBX>, NodeKDBXInte
fields[label] = value
}
fun getAttachments(binaryPool: BinaryPool): ArrayList<Attachment> {
val entryAttachmentList = ArrayList<Attachment>()
fun getAttachments(binaryPool: BinaryPool, inHistory: Boolean = false): Set<Attachment> {
val entryAttachmentList = HashSet<Attachment>()
for ((label, poolId) in binaries) {
binaryPool[poolId]?.let { binary ->
entryAttachmentList.add(Attachment(label, binary))
}
}
if (inHistory) {
history.forEach {
entryAttachmentList.addAll(it.getAttachments(binaryPool, false))
}
}
return entryAttachmentList
}

View File

@@ -317,7 +317,7 @@ class EntryContentsView @JvmOverloads constructor(context: Context,
attachmentsContainerView.visibility = if (show) View.VISIBLE else View.GONE
}
fun assignAttachments(attachments: ArrayList<Attachment>,
fun assignAttachments(attachments: Set<Attachment>,
streamDirection: StreamDirection,
onAttachmentClicked: (attachment: Attachment)->Unit) {
showAttachments(attachments.isNotEmpty())

View File

@@ -284,7 +284,7 @@ class EntryEditContentsView @JvmOverloads constructor(context: Context,
return attachmentsAdapter.itemsList.map { it.attachment }
}
fun assignAttachments(attachments: ArrayList<Attachment>,
fun assignAttachments(attachments: Set<Attachment>,
streamDirection: StreamDirection,
onDeleteItem: (attachment: Attachment)->Unit) {
attachmentsContainerView.visibility = if (attachments.isEmpty()) View.GONE else View.VISIBLE