|
|
|
|
@ -4,6 +4,7 @@ import kotlinx.coroutines.CoroutineStart
|
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
import kotlinx.coroutines.runInterruptible
|
|
|
|
|
import okhttp3.internal.closeQuietly
|
|
|
|
|
import okio.Closeable
|
|
|
|
|
import org.json.JSONArray
|
|
|
|
|
import org.koitharu.kotatsu.core.exceptions.BadBackupFormatException
|
|
|
|
|
@ -38,7 +39,7 @@ class BackupZipInput private constructor(val file: File) : Closeable {
|
|
|
|
|
fun cleanupAsync() {
|
|
|
|
|
processLifecycleScope.launch(Dispatchers.IO, CoroutineStart.ATOMIC) {
|
|
|
|
|
runCatching {
|
|
|
|
|
close()
|
|
|
|
|
closeQuietly()
|
|
|
|
|
file.delete()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -46,14 +47,22 @@ class BackupZipInput private constructor(val file: File) : Closeable {
|
|
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
|
|
|
|
|
fun from(file: File): BackupZipInput = try {
|
|
|
|
|
val res = BackupZipInput(file)
|
|
|
|
|
fun from(file: File): BackupZipInput {
|
|
|
|
|
var res: BackupZipInput? = null
|
|
|
|
|
return try {
|
|
|
|
|
res = BackupZipInput(file)
|
|
|
|
|
if (res.zipFile.getEntry("index") == null) {
|
|
|
|
|
throw BadBackupFormatException(null)
|
|
|
|
|
}
|
|
|
|
|
res
|
|
|
|
|
} catch (e: ZipException) {
|
|
|
|
|
throw BadBackupFormatException(e)
|
|
|
|
|
} catch (exception: Exception) {
|
|
|
|
|
res?.closeQuietly()
|
|
|
|
|
throw if (exception is ZipException) {
|
|
|
|
|
BadBackupFormatException(exception)
|
|
|
|
|
} else {
|
|
|
|
|
exception
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|