From fde8137b62a3d0cd8e4d94df6fde04f2f61cbbc9 Mon Sep 17 00:00:00 2001 From: Fabian Henneke Date: Wed, 25 Mar 2020 17:13:30 +0100 Subject: Delete AutofillMatches when deleting files (#659) --- .../java/com/zeapo/pwdstore/autofill/oreo/AutofillMatcher.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'app/src/main/java/com/zeapo/pwdstore/autofill') diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillMatcher.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillMatcher.kt index 5f9c081d..e6e16ef0 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillMatcher.kt +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/AutofillMatcher.kt @@ -148,10 +148,11 @@ class AutofillMatcher { /** * Goes through all existing matches and updates their associated entries by using - * [sourceDestinationMap] as a lookup table. + * [moveFromTo] as a lookup table and deleting the matches for files in [delete]. */ - fun updateMatchesFor(context: Context, sourceDestinationMap: Map) { - val oldNewPathMap = sourceDestinationMap.mapValues { it.value.absolutePath } + fun updateMatches(context: Context, moveFromTo: Map = emptyMap(), delete: Collection = emptyList()) { + val deletePathList = delete.map { it.absolutePath } + val oldNewPathMap = moveFromTo.mapValues { it.value.absolutePath } .mapKeys { it.key.absolutePath } for (prefs in listOf(context.autofillAppMatches, context.autofillWebMatches)) { for ((key, value) in prefs.all) { @@ -164,7 +165,10 @@ class AutofillMatcher { // Delete all matches for file locations that are going to be overwritten, then // transfer matches over to the files at their new locations. val newMatches = - oldMatches.asSequence().minus(oldNewPathMap.values).map { match -> + oldMatches.asSequence() + .minus(deletePathList) + .minus(oldNewPathMap.values) + .map { match -> val newPath = oldNewPathMap[match] ?: return@map match d { "Updating match for $key: $match --> $newPath" } newPath -- cgit v1.2.3