GH-853 evict asset index files from cache when they don't parse

This commit is contained in:
Petr Mrázek 2015-04-01 00:23:17 +02:00
parent eae544f0eb
commit 3b6574181e
3 changed files with 22 additions and 0 deletions

View File

@ -118,6 +118,9 @@ void OneSixUpdate::assetIndexFinished()
QString asset_fname = "assets/indexes/" + assetName + ".json"; QString asset_fname = "assets/indexes/" + assetName + ".json";
if (!AssetsUtils::loadAssetsIndexJson(asset_fname, &index)) if (!AssetsUtils::loadAssetsIndexJson(asset_fname, &index))
{ {
auto metacache = MMC->metacache();
auto entry = metacache->resolveEntry("asset_indexes", assetName + ".json");
metacache->evictEntry(entry);
emitFailed(tr("Failed to read the assets index!")); emitFailed(tr("Failed to read the assets index!"));
} }

View File

@ -135,6 +135,17 @@ bool HttpMetaCache::updateEntry(MetaEntryPtr stale_entry)
return true; return true;
} }
bool HttpMetaCache::evictEntry(MetaEntryPtr entry)
{
if(entry)
{
entry->stale = true;
SaveEventually();
return true;
}
return false;
}
MetaEntryPtr HttpMetaCache::staleEntry(QString base, QString resource_path) MetaEntryPtr HttpMetaCache::staleEntry(QString base, QString resource_path)
{ {
auto foo = new MetaEntry; auto foo = new MetaEntry;
@ -228,6 +239,11 @@ void HttpMetaCache::SaveNow()
{ {
for (auto entry : group.entry_list) for (auto entry : group.entry_list)
{ {
// do not save stale entries. they are dead.
if(entry->stale)
{
continue;
}
QJsonObject entryObj; QJsonObject entryObj;
entryObj.insert("base", QJsonValue(entry->base)); entryObj.insert("base", QJsonValue(entry->base));
entryObj.insert("path", QJsonValue(entry->path)); entryObj.insert("path", QJsonValue(entry->path));

View File

@ -51,6 +51,9 @@ public:
// add a previously resolved stale entry // add a previously resolved stale entry
bool updateEntry(MetaEntryPtr stale_entry); bool updateEntry(MetaEntryPtr stale_entry);
// evict selected entry from cache
bool evictEntry(MetaEntryPtr entry);
void addBase(QString base, QString base_root); void addBase(QString base, QString base_root);
// (re)start a timer that calls SaveNow later. // (re)start a timer that calls SaveNow later.