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
This commit is contained in:
Daniel Gultsch 2023-09-25 10:54:17 +02:00
parent 2adff4a92c
commit 3e9c08a4aa
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2

View file

@ -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()) {