From 59115ff9a34af63ba6e73a257aded19666a2a21b Mon Sep 17 00:00:00 2001 From: OneWay Date: Sun, 20 Sep 2026 23:11:54 +0800 Subject: [PATCH] fix: ignore dateless sources when checking dictionary freshness A source URL without the {DATE} placeholder is date-invariant, so its HEAD probe always answers 200. Including such sources in the freshness check made the checker report "server has a newer version" regardless of the dated sources' state. --- .../download/repository/DictionaryChecker.kt | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/example/research/feature/download/repository/DictionaryChecker.kt b/app/src/main/java/com/example/research/feature/download/repository/DictionaryChecker.kt index cf1b131..020ff20 100644 --- a/app/src/main/java/com/example/research/feature/download/repository/DictionaryChecker.kt +++ b/app/src/main/java/com/example/research/feature/download/repository/DictionaryChecker.kt @@ -64,7 +64,14 @@ class DictionaryChecker( val previousDate = DateUtils.getPreviousDateString() val dictFiles = getDictFiles(folderUri, files) - val allHaveToday = enabledSources.all { source -> + val datedSources = enabledSources.filter { source -> + DictionarySource.hasDatePlaceholder(source.urlTemplate) + } + if (datedSources.isEmpty()) { + return@withContext true + } + + val allHaveToday = datedSources.all { source -> dictFiles.hasFileForSource(source, currentDate) } @@ -72,19 +79,28 @@ class DictionaryChecker( return@withContext true } - val allHaveYesterday = enabledSources.all { source -> + val allHaveYesterday = datedSources.all { source -> dictFiles.hasFileForSource(source, previousDate) } if (allHaveYesterday) { - val serverHasToday = enabledSources.any { source -> + val serverHasToday = datedSources.any { source -> isSourceAvailableOnServer(source, currentDate) } return@withContext !serverHasToday } - false + val serverCanOfferNewer = datedSources.any { source -> + when (probeSource(source, currentDate)) { + SourceAvailability.AVAILABLE -> true + SourceAvailability.NOT_FOUND -> + probeSource(source, previousDate) == SourceAvailability.AVAILABLE + SourceAvailability.UNKNOWN -> false + } + } + + return@withContext !serverCanOfferNewer } catch (e: Exception) { Log.e(TAG, "Error checking currency: ${e.message}", e) false