mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Remove oldest attachments files when deleted from entries
This commit is contained in:
@@ -361,7 +361,7 @@ class EntryEditActivity : LockingActivity(),
|
||||
|
||||
mDatabase?.binaryPool?.let { binaryPool ->
|
||||
assignAttachments(newEntry.getAttachments(binaryPool), StreamDirection.UPLOAD) { attachment ->
|
||||
newEntry.removeAttachment(attachment, binaryPool)
|
||||
newEntry.removeAttachment(attachment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ open class SaveDatabaseRunnable(protected var context: Context,
|
||||
override fun onStartRun() {}
|
||||
|
||||
override fun onActionRun() {
|
||||
// TODO as setting database.removeUnlinkedAttachments()
|
||||
if (saveDatabase && result.isSuccess) {
|
||||
try {
|
||||
database.saveData(context.contentResolver)
|
||||
|
||||
@@ -64,6 +64,10 @@ class DeleteNodesRunnable(context: Context,
|
||||
} else {
|
||||
database.deleteEntry(currentNode)
|
||||
}
|
||||
// Remove the oldest attachments
|
||||
currentNode.getAttachments(database.binaryPool).forEach {
|
||||
database.removeAttachmentIfNotUsed(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package com.kunzisoft.keepass.database.action.node
|
||||
|
||||
import android.content.Context
|
||||
import com.kunzisoft.keepass.database.element.Attachment
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.Entry
|
||||
import com.kunzisoft.keepass.database.element.node.Node
|
||||
@@ -40,6 +41,12 @@ class UpdateEntryRunnable constructor(
|
||||
// WARNING : Re attribute parent removed in entry edit activity to save memory
|
||||
mNewEntry.addParentFrom(mOldEntry)
|
||||
|
||||
// Build oldest attachments
|
||||
val oldEntryAttachments = mOldEntry.getAttachments(database.binaryPool)
|
||||
val newEntryAttachments = mNewEntry.getAttachments(database.binaryPool)
|
||||
val differenceAttachments = ArrayList<Attachment>(oldEntryAttachments)
|
||||
differenceAttachments.removeAll(newEntryAttachments)
|
||||
|
||||
// Update entry with new values
|
||||
mOldEntry.updateWith(mNewEntry)
|
||||
mNewEntry.touch(modified = true, touchParents = true)
|
||||
@@ -50,6 +57,11 @@ class UpdateEntryRunnable constructor(
|
||||
|
||||
// Only change data in index
|
||||
database.updateEntry(mOldEntry)
|
||||
|
||||
// Remove oldest attachments
|
||||
differenceAttachments.forEach {
|
||||
database.removeAttachmentIfNotUsed(it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun nodeFinish(): ActionNodesValues {
|
||||
|
||||
@@ -346,9 +346,9 @@ class Entry : Node, EntryVersionedInterface<Group> {
|
||||
entryKDBX?.putAttachment(attachment, binaryPool)
|
||||
}
|
||||
|
||||
fun removeAttachment(attachment: Attachment, binaryPool: BinaryPool) {
|
||||
fun removeAttachment(attachment: Attachment) {
|
||||
entryKDB?.removeAttachment(attachment)
|
||||
entryKDBX?.removeAttachment(attachment, binaryPool)
|
||||
entryKDBX?.removeAttachment(attachment)
|
||||
}
|
||||
|
||||
fun getHistory(): ArrayList<Entry> {
|
||||
|
||||
@@ -305,9 +305,8 @@ class EntryKDBX : EntryVersioned<UUID, UUID, GroupKDBX, EntryKDBX>, NodeKDBXInte
|
||||
binaries[attachment.name] = binaryPool.put(attachment.binaryAttachment)
|
||||
}
|
||||
|
||||
fun removeAttachment(attachment: Attachment, binaryPool: BinaryPool) {
|
||||
fun removeAttachment(attachment: Attachment) {
|
||||
binaries.remove(attachment.name)
|
||||
binaryPool.remove(attachment.binaryAttachment)
|
||||
}
|
||||
|
||||
private fun getAttachmentsSize(binaryPool: BinaryPool): Long {
|
||||
|
||||
Reference in New Issue
Block a user