From de853a2651d12fd44c22fc0e9b0f3bbbab766ea3 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 14 Jan 2020 22:03:29 +0800 Subject: [PATCH] Fix crash when manually refresh repo db --- .../magisk/core/tasks/RepoUpdater.kt | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/tasks/RepoUpdater.kt b/app/src/main/java/com/topjohnwu/magisk/core/tasks/RepoUpdater.kt index e8b4f2dfd..895a7634a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/tasks/RepoUpdater.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/tasks/RepoUpdater.kt @@ -39,7 +39,7 @@ class RepoUpdater( it.error()?.also { throw it } it.response()?.run { if (code() == HttpURLConnection.HTTP_NOT_MODIFIED) - return@run Flowable.error(CachedException) + return@run Flowable.error(CachedException()) if (page == 1) repoDB.etagKey = headers()[Const.Key.ETAG_KEY].orEmpty().trimEtag() @@ -64,21 +64,23 @@ class RepoUpdater( @Suppress("RedundantLambdaArrow") operator fun invoke(forced: Boolean = false) : Completable { - val cached = Collections.synchronizedSet(HashSet(repoDB.repoIDList)) - return loadPage(cached, etag = repoDB.etagKey).doOnComplete { - repoDB.removeRepos(cached) - }.onErrorResumeNext { it: Throwable -> - if (it is CachedException) { - if (forced) - return@onErrorResumeNext forcedReload(cached) - } else { - Timber.e(it) - } - Flowable.empty() - }.ignoreElements() + return Flowable.fromCallable { Collections.synchronizedSet(HashSet(repoDB.repoIDList)) } + .flatMap { cached -> + loadPage(cached, etag = repoDB.etagKey).doOnComplete { + repoDB.removeRepos(cached) + }.onErrorResumeNext { it: Throwable -> + if (it is CachedException) { + if (forced) + return@onErrorResumeNext forcedReload(cached) + } else { + Timber.e(it) + } + Flowable.empty() + } + }.ignoreElements() } - object CachedException : Exception() + class CachedException : Exception() } private val dateFormat: SimpleDateFormat =