Skip to content

Commit a5ccb5d

Browse files
authored
Merge pull request #44 from harissabil/fix-google-drive-empty-file
Fix empty backup file when saving to Google Drive (#18)
2 parents 2b73f4d + dccae14 commit a5ccb5d

File tree

1 file changed

+8
-2
lines changed
  • core/src/main/java/de/raphaelebner/roomdatabasebackup/core

1 file changed

+8
-2
lines changed

core/src/main/java/de/raphaelebner/roomdatabasebackup/core/RoomBackup.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,13 +417,19 @@ class RoomBackup(var context: Context) {
417417
// Close the database
418418
roomDatabase!!.close()
419419
roomDatabase = null
420+
421+
val bos = BufferedOutputStream(destination)
420422
if (backupIsEncrypted) {
421423
val encryptedBytes = encryptBackup() ?: return
422-
destination.write(encryptedBytes)
424+
bos.write(encryptedBytes)
423425
} else {
424426
// Copy current database to save location (/files dir)
425-
copy(DATABASE_FILE, destination)
427+
val inputStream = DATABASE_FILE.inputStream().buffered()
428+
inputStream.copyTo(bos)
429+
inputStream.close()
426430
}
431+
bos.flush()
432+
bos.close()
427433

428434
// If maxFileCount is set and is reached, delete oldest file
429435
if (maxFileCount != null) {

0 commit comments

Comments
 (0)