From 3e9c08a4aa8484a514bfdc68c33c6eaa27bec1fe Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 25 Sep 2023 10:54:17 +0200 Subject: [PATCH] include date in backup file name since `account.ceb` might have previously been created by a different application (for example f-droid and user is on play now) or copied over via the file manager Conversations might not have permission to write over an existing file. we include the date so we always get a new file fixes #105 --- .../conversations/services/ExportBackupService.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/ExportBackupService.java b/src/main/java/eu/siacs/conversations/services/ExportBackupService.java index 442fc5f4f..1462b5614 100644 --- a/src/main/java/eu/siacs/conversations/services/ExportBackupService.java +++ b/src/main/java/eu/siacs/conversations/services/ExportBackupService.java @@ -31,10 +31,13 @@ import java.nio.charset.StandardCharsets; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.security.spec.InvalidKeySpecException; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.concurrent.atomic.AtomicBoolean; import java.util.zip.GZIPOutputStream; @@ -58,6 +61,8 @@ import eu.siacs.conversations.utils.Compatibility; public class ExportBackupService extends Service { + private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd", Locale.US); + public static final String KEYTYPE = "AES"; public static final String CIPHERMODE = "AES/GCM/NoPadding"; public static final String PROVIDER = "BC"; @@ -296,10 +301,14 @@ public class ExportBackupService extends Service { IV, salt); final Progress progress = new Progress(mBuilder, max, count); + final String filename = + String.format( + "%s.%s.ceb", + account.getJid().asBareJid().toEscapedString(), + DATE_FORMAT.format(new Date())); final File file = new File( - FileBackend.getBackupDirectory(this), - account.getJid().asBareJid().toEscapedString() + ".ceb"); + FileBackend.getBackupDirectory(this), filename); files.add(file); final File directory = file.getParentFile(); if (directory != null && directory.mkdirs()) {