fix(download): verify payload freshness before restoring the update state
On restart the update-available state was restored purely from the saved date. Also compare the installed payload file names against dated sources, and re-check when they no longer match.
This commit is contained in:
1 parent
6146c0ebfe
commit
344852a871
1 file changed
+23
-1
@@ -524,6 +524,25 @@ class SettingsViewModel(
|
||||
): List<DictionarySource> =
|
||||
DictionarySourceFileMatcher.installedSources(sources, dictionaries)
|
||||
|
||||
private suspend fun installedDictionariesAreCurrent(): Boolean {
|
||||
val sources = preferencesManager.dictionarySources.first()
|
||||
val dictionaries = localDictionaryRepository.dictionaries.first()
|
||||
val datedEnabledSources = installedEnabledSources(sources, dictionaries)
|
||||
.filter { DictionarySource.hasDatePlaceholder(it.urlTemplate) }
|
||||
if (datedEnabledSources.isEmpty()) return true
|
||||
val fileNames = localDictionaryRepository.listDictionaryPayloadFileNames(
|
||||
preferencesManager.dictionaryPath
|
||||
) ?: return true
|
||||
val today = DateUtils.getCurrentDateString()
|
||||
return datedEnabledSources.all { source ->
|
||||
val baseName = DictionarySource.extractFileName(source.urlTemplate, today)
|
||||
.removeSuffix(".gz")
|
||||
.removeSuffix(".dsl")
|
||||
.removeSuffix(".dz")
|
||||
fileNames.any { it.startsWith(baseName) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun cancelDownload() {
|
||||
// Cancel the ViewModel-side scan job so no further status recomputes
|
||||
localDictionaryRepository.cancelIndexing()
|
||||
@@ -584,7 +603,10 @@ class SettingsViewModel(
|
||||
"NeedsUpdate" -> DictionaryStatus.NeedsUpdate
|
||||
else -> null
|
||||
}
|
||||
if (restoredStatus != null && savedStatusDate == DateUtils.getCurrentDateString()) {
|
||||
if (restoredStatus != null &&
|
||||
savedStatusDate == DateUtils.getCurrentDateString() &&
|
||||
withContext(Dispatchers.IO) { installedDictionariesAreCurrent() }
|
||||
) {
|
||||
dictionaryStatus.value = restoredStatus
|
||||
} else {
|
||||
dictionaryStatus.value = DictionaryStatus.Checking
|
||||
|
||||
Reference in new issue
Block a user