mirror of
https://github.com/mihonapp/mihon.git
synced 2025-02-17 03:22:22 +00:00
Avoid potentially deleting the entire backups folder
This commit is contained in:
parent
b47b702a52
commit
45da036789
1 changed files with 5 additions and 1 deletions
|
@ -85,9 +85,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
|
||||||
|
|
Loading…
Reference in a new issue