From 682a2c754671573e7f2ac58d8a8a6ebee03d4583 Mon Sep 17 00:00:00 2001 From: len Date: Thu, 9 Jun 2016 15:46:08 +0200 Subject: [PATCH] Delete file when exception is thrown --- .../eu/kanade/tachiyomi/data/download/DownloadManager.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt index 5a907ccbb..f4360cd95 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt @@ -258,16 +258,17 @@ class DownloadManager(private val context: Context, private val sourceManager: S private fun downloadImage(page: Page, source: OnlineSource, directory: File, filename: String): Observable { page.status = Page.DOWNLOAD_IMAGE return source.imageResponse(page) - .flatMap { + .map { + val file = File(directory, filename) try { - val file = File(directory, filename) file.parentFile.mkdirs() it.body().source().saveImageTo(file.outputStream(), preferences.reencodeImage()) } catch (e: Exception) { - it.body().close() + it.close() + file.delete() throw e } - Observable.just(page) + page } .retryWhen { it.zipWith(Observable.range(1, 3)) { errors, retries -> retries }