From dccae144981a7de091bbe65e5a4b5b85deb3f0b0 Mon Sep 17 00:00:00 2001 From: Haris Date: Mon, 10 Mar 2025 20:20:01 +0700 Subject: [PATCH] Fix empty Google Drive backups --- .../raphaelebner/roomdatabasebackup/core/RoomBackup.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/de/raphaelebner/roomdatabasebackup/core/RoomBackup.kt b/core/src/main/java/de/raphaelebner/roomdatabasebackup/core/RoomBackup.kt index a908245..12d1775 100644 --- a/core/src/main/java/de/raphaelebner/roomdatabasebackup/core/RoomBackup.kt +++ b/core/src/main/java/de/raphaelebner/roomdatabasebackup/core/RoomBackup.kt @@ -417,13 +417,19 @@ class RoomBackup(var context: Context) { // Close the database roomDatabase!!.close() roomDatabase = null + + val bos = BufferedOutputStream(destination) if (backupIsEncrypted) { val encryptedBytes = encryptBackup() ?: return - destination.write(encryptedBytes) + bos.write(encryptedBytes) } else { // Copy current database to save location (/files dir) - copy(DATABASE_FILE, destination) + val inputStream = DATABASE_FILE.inputStream().buffered() + inputStream.copyTo(bos) + inputStream.close() } + bos.flush() + bos.close() // If maxFileCount is set and is reached, delete oldest file if (maxFileCount != null) {