diff --git a/CHANGELOG b/CHANGELOG index ede1134b9..23c050b41 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +KeePassDX(4.2.2) + * Fix database merge algorithm #2223 + KeePassDX(4.2.1) * Fix Magikeyboard autosearch #2233 * Fix database merge #2223 diff --git a/app/build.gradle b/app/build.gradle index 21fe4d380..c154fe923 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,8 +11,8 @@ android { applicationId "com.kunzisoft.keepass" minSdkVersion 19 targetSdkVersion 35 - versionCode = 146 - versionName = "4.2.1" + versionCode = 147 + versionName = "4.2.2" multiDexEnabled true testApplicationId = "com.kunzisoft.keepass.tests" diff --git a/database/src/main/java/com/kunzisoft/keepass/database/merge/DatabaseKDBXMerger.kt b/database/src/main/java/com/kunzisoft/keepass/database/merge/DatabaseKDBXMerger.kt index 3f9ef8f07..982b9e5d0 100644 --- a/database/src/main/java/com/kunzisoft/keepass/database/merge/DatabaseKDBXMerger.kt +++ b/database/src/main/java/com/kunzisoft/keepass/database/merge/DatabaseKDBXMerger.kt @@ -510,54 +510,46 @@ class DatabaseKDBXMerger(private var database: DatabaseKDBX) { // Merge by modification time if (entry.lastModificationTime.isBefore(entryToMerge.lastModificationTime)) { // Update entry with databaseEntryToMerge and merge history - addHistory(entry, entryToMerge) - if (parentEntryToMerge == entry.parent) { - // Update the current entry to keep modification - entry.updateWith(entryToMerge, copyHistory = true, updateParents = false) - // Move the current entry to the verified location - database.removeEntryFrom(entry, entry.parent) - database.addEntryTo(entry, parentEntryToMerge) - } else { - // Remove the current entry and add the entry to merge to the correct location - database.removeEntryFrom(entry, entry.parent) - database.addEntryTo(entryToMerge, parentEntryToMerge) - } + entryToMerge.addHistoryFrom(entry) + entry.updateWith(entryToMerge, copyHistory = true, updateParents = false) + // Move the current entry to the verified location + database.removeEntryFrom(entry, entry.parent) + database.addEntryTo(entry, parentEntryToMerge) } else if (entry.lastModificationTime.isAfter(entryToMerge.lastModificationTime)) { // Don't touch the location but update the entry history - addHistory(entryToMerge, entry) + entry.addHistoryFrom(entryToMerge) } else if (entry.lastModificationTime.isEquals(entryToMerge.lastModificationTime)) { // If it's the same modification time, simply move entry to the right location, // Current entry and entry to merge are normally the same database.removeEntryFrom(entry, entry.parent) - database.addEntryTo(entryToMerge, parentEntryToMerge) + database.addEntryTo(entry, parentEntryToMerge) } } } } /** - * Utility method to merge an history from an [entryA] to an [entryB], - * [entryB] is modified + * Utility method to merge an history from an [entryA] */ - private fun addHistory(entryA: EntryKDBX, entryB: EntryKDBX) { + private fun EntryKDBX.addHistoryFrom(entryA: EntryKDBX) { // Keep entry as history if already not present entryA.history.forEach { history -> // If history not present - if (!entryB.history.any { + if (!this.history.any { it.lastModificationTime == history.lastModificationTime }) { - entryB.addEntryToHistory(history) + this.addEntryToHistory(history) } } // Last entry not present - if (entryB.history.find { + if (this.history.find { it.lastModificationTime == entryA.lastModificationTime } == null) { val history = EntryKDBX().apply { updateWith(entryA, copyHistory = false, updateParents = false) parent = null } - entryB.addEntryToHistory(history) + this.addEntryToHistory(history) } } @@ -587,19 +579,16 @@ class DatabaseKDBXMerger(private var database: DatabaseKDBX) { mergeCustomData(group.customData, groupToMerge.customData) // Merge by modification time if (group.lastModificationTime.isBefore(groupToMerge.lastModificationTime)) { - if (parentGroupToMerge == group.parent) { - group.updateWith(groupToMerge, updateParents = false) - // Update the current group location to the verified one - database.removeGroupFrom(group, group.parent) - database.addGroupTo(group, parentGroupToMerge) - } else { - database.removeGroupFrom(group, group.parent) - database.addGroupTo(groupToMerge, parentGroupToMerge) - } + group.updateWith(groupToMerge, updateParents = false) + // Update the current group location to the verified one + database.removeGroupFrom(group, group.parent) + database.addGroupTo(group, parentGroupToMerge) + } else if (group.lastModificationTime.isAfter(group.lastModificationTime)) { + // Don't touch the location } else if (group.lastModificationTime.isEquals(groupToMerge.lastModificationTime)) { // If it's the same modification time, simply move group to the right location database.removeGroupFrom(group, group.parent) - database.addGroupTo(groupToMerge, parentGroupToMerge) + database.addGroupTo(group, parentGroupToMerge) } } } diff --git a/fastlane/metadata/android/en-US/changelogs/147.txt b/fastlane/metadata/android/en-US/changelogs/147.txt new file mode 100644 index 000000000..db2d01af9 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/147.txt @@ -0,0 +1 @@ + * Fix database merge algorithm #2223 \ No newline at end of file diff --git a/fastlane/metadata/android/fr-FR/changelogs/147.txt b/fastlane/metadata/android/fr-FR/changelogs/147.txt new file mode 100644 index 000000000..94fba0dd3 --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/147.txt @@ -0,0 +1 @@ + * Correction de l'algorithme de fusion des bases de données #2223 \ No newline at end of file