mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 17:48:33 +00:00
Make better effort to delete leftover temporary backup files.
This commit is contained in:
parent
5d54ebfaa0
commit
3589fa381d
@ -85,10 +85,12 @@ public static void export(@NonNull Context context,
|
|||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
BackupFrameOutputStream outputStream = new BackupFrameOutputStream(output, passphrase);
|
BackupFrameOutputStream outputStream = new BackupFrameOutputStream(output, passphrase);
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
try {
|
||||||
outputStream.writeDatabaseVersion(input.getVersion());
|
outputStream.writeDatabaseVersion(input.getVersion());
|
||||||
|
|
||||||
List<String> tables = exportSchema(input, outputStream);
|
List<String> tables = exportSchema(input, outputStream);
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
Stopwatch stopwatch = new Stopwatch("Backup");
|
Stopwatch stopwatch = new Stopwatch("Backup");
|
||||||
|
|
||||||
@ -123,9 +125,11 @@ public static void export(@NonNull Context context,
|
|||||||
stopwatch.stop(TAG);
|
stopwatch.stop(TAG);
|
||||||
|
|
||||||
outputStream.writeEnd();
|
outputStream.writeEnd();
|
||||||
|
} finally {
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
EventBus.getDefault().post(new BackupEvent(BackupEvent.Type.FINISHED, ++count));
|
EventBus.getDefault().post(new BackupEvent(BackupEvent.Type.FINISHED, ++count));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static List<String> exportSchema(@NonNull SQLiteDatabase input, @NonNull BackupFrameOutputStream outputStream)
|
private static List<String> exportSchema(@NonNull SQLiteDatabase input, @NonNull BackupFrameOutputStream outputStream)
|
||||||
throws IOException
|
throws IOException
|
||||||
|
@ -86,6 +86,7 @@ public class LocalBackupJob extends BaseJob {
|
|||||||
|
|
||||||
File tempFile = File.createTempFile("backup", "tmp", StorageUtil.getBackupCacheDirectory(context));
|
File tempFile = File.createTempFile("backup", "tmp", StorageUtil.getBackupCacheDirectory(context));
|
||||||
|
|
||||||
|
try {
|
||||||
FullBackupExporter.export(context,
|
FullBackupExporter.export(context,
|
||||||
AttachmentSecretProvider.getInstance(context).getOrCreateAttachmentSecret(),
|
AttachmentSecretProvider.getInstance(context).getOrCreateAttachmentSecret(),
|
||||||
DatabaseFactory.getBackupDatabase(context),
|
DatabaseFactory.getBackupDatabase(context),
|
||||||
@ -93,9 +94,18 @@ public class LocalBackupJob extends BaseJob {
|
|||||||
backupPassword);
|
backupPassword);
|
||||||
|
|
||||||
if (!tempFile.renameTo(backupFile)) {
|
if (!tempFile.renameTo(backupFile)) {
|
||||||
tempFile.delete();
|
Log.w(TAG, "Failed to rename temp file");
|
||||||
throw new IOException("Renaming temporary backup file failed!");
|
throw new IOException("Renaming temporary backup file failed!");
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
if (tempFile.exists()) {
|
||||||
|
if (tempFile.delete()) {
|
||||||
|
Log.w(TAG, "Backup failed. Deleted temp file");
|
||||||
|
} else {
|
||||||
|
Log.w(TAG, "Backup failed. Failed to delete temp file " + tempFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BackupUtil.deleteOldBackups();
|
BackupUtil.deleteOldBackups();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user