From 3b55a14acbf8845067f0ab0789a14c6faff8601e Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Wed, 27 Jan 2021 11:12:23 +0530 Subject: Disallow overwriting passwords when editing (#1286) Co-authored-by: Aditya Wasan (cherry picked from commit 1f8db46ade8a7c25deb568b8a5988ee7b340b9c1) --- .../main/java/com/zeapo/pwdstore/crypto/PasswordCreationActivity.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app/src') diff --git a/app/src/main/java/com/zeapo/pwdstore/crypto/PasswordCreationActivity.kt b/app/src/main/java/com/zeapo/pwdstore/crypto/PasswordCreationActivity.kt index 94a32ea4..baabfbf5 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/PasswordCreationActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PasswordCreationActivity.kt @@ -397,7 +397,10 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB runCatching { val file = File(path) // If we're not editing, this file should not already exist! - if (!editing && file.exists()) { + // Additionally, if we were editing and the incoming and outgoing + // filenames differ, it means we renamed. Ensure that the target + // doesn't already exist to prevent an accidental overwrite. + if ((!editing || (editing && suggestedName != file.nameWithoutExtension)) && file.exists()) { snackbar(message = getString(R.string.password_creation_duplicate_error)) return@executeApiAsync } -- cgit v1.2.3