summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorحسين <zidhussein@gmail.com>2018-12-25 21:35:08 +0000
committerحسين <zidhussein@gmail.com>2018-12-25 21:35:08 +0000
commit054056fa221e13fd58b41ecc66bfaa1d24baea81 (patch)
tree39f4e799dd8b9df23f3ba043a23a86f972ca00ac /app
parent9496ed31fdd6525a738eb781e567a8a723d577c2 (diff)
alert user when password is being overridden
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordStore.java31
1 files changed, 22 insertions, 9 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java
index d79e7c19..0c8d5b39 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordStore.java
@@ -716,19 +716,32 @@ public class PasswordStore extends AppCompatActivity {
continue;
}
+ File destinationFile = new File(target.getAbsolutePath() + "/" + source.getName());
+
+ String basename = FilenameUtils.getBaseName(source.getAbsolutePath());
+
+ String sourceLongName = PgpActivity.getLongName(source.getParent(),
+ repositoryPath, basename);
+
+ String destinationLongName = PgpActivity.getLongName(target.getAbsolutePath(),
+ repositoryPath, basename);
+
+ if (destinationFile.exists()) {
+ Log.e("Moving", "Trying to move a file that already exists.");
+ // TODO: Add option to cancel overwrite. Will be easier once this is an async task.
+ // TODO: Replace with resource strings
+ new AlertDialog.Builder(this)
+ .setTitle("Password already exists!")
+ .setMessage(String.format("This will overwrite %1$s with %2$s.",
+ destinationLongName, sourceLongName))
+ .setPositiveButton("Okay", null)
+ .show();
+ }
- if (!source.renameTo(new File(target.getAbsolutePath() + "/" + source.getName()))) {
+ if (!source.renameTo(destinationFile)) {
// TODO this should show a warning to the user
Log.e("Moving", "Something went wrong while moving.");
} else {
- String basename = FilenameUtils.getBaseName(source.getAbsolutePath());
-
- String sourceLongName = PgpActivity.getLongName(source.getParent(),
- repositoryPath, basename);
-
- String destinationLongName = PgpActivity.getLongName(target.getAbsolutePath(),
- repositoryPath, basename);
-
commitChange(this.getResources()
.getString(R.string.git_commit_move_text,
sourceLongName,