Avoid potentially deleting the entire backups folder

(cherry picked from commit 45da0367890fa27b5c9dd553960cf7f9fb06e099)
This commit is contained in:
arkon 2022-03-09 18:01:43 -05:00 committed by Jobobby04
parent 0b2dabc7fa
commit 324280aed4

View File

@ -108,9 +108,13 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) {
) )
?: throw Exception("Couldn't create backup file") ?: throw Exception("Couldn't create backup file")
if (!file.isFile) {
throw IllegalStateException("Failed to get handle on file")
}
val byteArray = parser.encodeToByteArray(BackupSerializer, backup!!) val byteArray = parser.encodeToByteArray(BackupSerializer, backup!!)
file.openOutputStream().also { file.openOutputStream().also {
// Force overwrite old file size, // Force overwrite old file
(it as? FileOutputStream)?.channel?.truncate(0) (it as? FileOutputStream)?.channel?.truncate(0)
}.sink().gzip().buffer().use { it.write(byteArray) } }.sink().gzip().buffer().use { it.write(byteArray) }
val fileUri = file.uri val fileUri = file.uri