From 744823cce4e33d89fe246feb25e4f26669a60645 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Tue, 2 Mar 2021 14:43:48 +0100 Subject: [PATCH] Fix unique id for each binary file --- .../keepass/database/element/database/BinaryPool.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/kunzisoft/keepass/database/element/database/BinaryPool.kt b/app/src/main/java/com/kunzisoft/keepass/database/element/database/BinaryPool.kt index 1d7e71d96..a94281a88 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/element/database/BinaryPool.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/element/database/BinaryPool.kt @@ -21,12 +21,16 @@ package com.kunzisoft.keepass.database.element.database import java.io.File import java.io.IOException +import kotlin.math.abs abstract class BinaryPool { protected val pool = LinkedHashMap() - private var binaryFileIncrement = 0L // Unique file id (don't use current time because CPU too fast) + // To build unique file id + private var creationId: String = System.currentTimeMillis().toString() + private var poolId: String = abs(javaClass.simpleName.hashCode()).toString() + private var binaryFileIncrement = 0L /** * To get a binary by the pool key (ref attribute in entry) @@ -42,7 +46,7 @@ abstract class BinaryPool { key: T? = null, compression: Boolean = false, protection: Boolean = false): KeyBinary { - val fileInCache = File(cacheDirectory, binaryFileIncrement.toString()) + val fileInCache = File(cacheDirectory, "$poolId$creationId$binaryFileIncrement") binaryFileIncrement++ val newBinaryFile = BinaryFile(fileInCache, compression, protection) val newKey = put(key, newBinaryFile)