From 45da0367890fa27b5c9dd553960cf7f9fb06e099 Mon Sep 17 00:00:00 2001 From: arkon Date: Wed, 9 Mar 2022 18:01:43 -0500 Subject: [PATCH] Avoid potentially deleting the entire backups folder --- .../kanade/tachiyomi/data/backup/full/FullBackupManager.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt index 134c034ff..aaa1f03b4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt @@ -85,9 +85,13 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) { ) ?: throw Exception("Couldn't create backup file") + if (!file.isFile) { + throw IllegalStateException("Failed to get handle on file") + } + val byteArray = parser.encodeToByteArray(BackupSerializer, backup!!) file.openOutputStream().also { - // Force overwrite old file size, + // Force overwrite old file (it as? FileOutputStream)?.channel?.truncate(0) }.sink().gzip().buffer().use { it.write(byteArray) } val fileUri = file.uri