mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 07:31:50 +01:00
Delete file when exception is thrown
This commit is contained in:
parent
2d1e85f280
commit
682a2c7546
@ -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> {
|
private fun downloadImage(page: Page, source: OnlineSource, directory: File, filename: String): Observable<Page> {
|
||||||
page.status = Page.DOWNLOAD_IMAGE
|
page.status = Page.DOWNLOAD_IMAGE
|
||||||
return source.imageResponse(page)
|
return source.imageResponse(page)
|
||||||
.flatMap {
|
.map {
|
||||||
try {
|
|
||||||
val file = File(directory, filename)
|
val file = File(directory, filename)
|
||||||
|
try {
|
||||||
file.parentFile.mkdirs()
|
file.parentFile.mkdirs()
|
||||||
it.body().source().saveImageTo(file.outputStream(), preferences.reencodeImage())
|
it.body().source().saveImageTo(file.outputStream(), preferences.reencodeImage())
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
it.body().close()
|
it.close()
|
||||||
|
file.delete()
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
Observable.just(page)
|
page
|
||||||
}
|
}
|
||||||
.retryWhen {
|
.retryWhen {
|
||||||
it.zipWith(Observable.range(1, 3)) { errors, retries -> retries }
|
it.zipWith(Observable.range(1, 3)) { errors, retries -> retries }
|
||||||
|
Loading…
Reference in New Issue
Block a user