[fix] do not accept invalid cache and do not assume we have cache

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/89/head
androidacy-user 2 years ago
parent 7adc736804
commit b57c2a2fdd

@ -293,7 +293,12 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
) )
var lastLastUpdate: Long = 0 var lastLastUpdate: Long = 0
for (i in 0 until len) { for (i in 0 until len) {
jsonObject = jsonArray.getJSONObject(i) try {
jsonObject = jsonArray.getJSONObject(i)
} catch (e: JSONException) {
Timber.e(e, "Failed to parse module")
continue
}
val moduleId: String = try { val moduleId: String = try {
jsonObject.getString("codename") jsonObject.getString("codename")
} catch (e: JSONException) { } catch (e: JSONException) {

@ -61,46 +61,51 @@ class RepoUpdater(repoData2: RepoData) {
val moduleListCacheDao = db.moduleListCacheDao() val moduleListCacheDao = db.moduleListCacheDao()
// now we have the cache, we need to check if it's up to date // now we have the cache, we need to check if it's up to date
val results = moduleListCacheDao.getByRepoId(repoData.preferenceId!!) val results = moduleListCacheDao.getByRepoId(repoData.preferenceId!!)
toUpdate = emptyList() if (results.isNotEmpty()) {
toApply = HashSet() toUpdate = emptyList()
for (moduleListCache in results) { toApply = HashSet()
(toApply as HashSet<RepoModule>).add( for (moduleListCache in results) {
RepoModule( (toApply as HashSet<RepoModule>).add(
repoData, RepoModule(
moduleListCache.codename, repoData,
moduleListCache.name, moduleListCache.codename,
moduleListCache.description, moduleListCache.name,
moduleListCache.author, moduleListCache.description,
moduleListCache.donate, moduleListCache.author,
moduleListCache.config, moduleListCache.donate,
moduleListCache.support, moduleListCache.config,
moduleListCache.version, moduleListCache.support,
moduleListCache.versionCode moduleListCache.version,
moduleListCache.versionCode
)
) )
}
Timber.d(
"Fetched %d modules from cache for %s, from %s records",
(toApply as HashSet<RepoModule>).size,
repoData.preferenceId,
results.size
) )
val jsonObject = JSONObject()
// apply the toApply list to the toUpdate list
try {
jsonObject.put("modules", JSONArray(results))
toUpdate = repoData.populate(jsonObject)
} catch (e: Exception) {
Timber.e(e)
}
// log first 100 chars of indexRaw
indexRaw = jsonObject.toString().toByteArray()
Timber.d(
"Index raw: %s",
String(indexRaw!!, StandardCharsets.UTF_8).subSequence(0, 100)
)
// Since we reuse instances this should work
toApply = HashSet(repoData.moduleHashMap.values)
(toApply as HashSet<RepoModule>).removeAll(toUpdate!!.toSet())
// Return repo to update
return toUpdate!!.size
} }
Timber.d(
"Fetched %d modules from cache for %s, from %s records",
(toApply as HashSet<RepoModule>).size,
repoData.preferenceId,
results.size
)
val jsonObject = JSONObject()
// apply the toApply list to the toUpdate list
try {
jsonObject.put("modules", JSONArray(results))
toUpdate = repoData.populate(jsonObject)
} catch (e: Exception) {
Timber.e(e)
}
// log first 100 chars of indexRaw
indexRaw = jsonObject.toString().toByteArray()
Timber.d("Index raw: %s", String(indexRaw!!, StandardCharsets.UTF_8).subSequence(0, 100))
// Since we reuse instances this should work
toApply = HashSet(repoData.moduleHashMap.values)
(toApply as HashSet<RepoModule>).removeAll(toUpdate!!.toSet())
// Return repo to update
return toUpdate!!.size
} }
return try { return try {
if (!repoData.prepare()) { if (!repoData.prepare()) {

Loading…
Cancel
Save