Add check-then-fix code to ensure diff-path name in sync

There is a lot asynchronicity in the auto-update code, and
the fix here is to detect then fix instances of out of sync
state between a cached filter list and its metadata stored
separately.
This commit is contained in:
Raymond Hill 2023-11-11 15:51:59 -05:00
parent 4422926b63
commit e30223c42e
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 13 additions and 2 deletions

View File

@ -1242,6 +1242,16 @@ async function diffUpdater() {
if ( typeof error !== 'string' ) { return; }
ubolog(`Diff updater: terminate because ${error}`);
};
const checkAndCorrectDiffPath = data => {
if ( typeof data.text !== 'string' ) { return; }
if ( data.text === '' ) { return; }
const assetKey = assetKeyFromDiffName(data.name);
if ( assetKey === '' ) { return; }
const metadata = extractMetadataFromList(data.text, [ 'Diff-Path' ]);
if ( metadata instanceof Object === false ) { return; }
if ( metadata.diffPath === data.patchPath ) { return; }
assetCacheSetDetails(assetKey, metadata.diffPath);
};
bc.onmessage = ev => {
const data = ev.data;
if ( data.what === 'ready' ) {
@ -1285,9 +1295,10 @@ async function diffUpdater() {
assetCacheSetDetails(assetKey, metadata);
updaterUpdated.push(assetKey);
} else if ( data.error ) {
ubolog(`Diff updater: failed to update ${data.name} using ${data.patchPath}, reason: ${data.error}`);
ubolog(`Diff updater: failed to update ${data.name} using ${data.patchPath}\n\treason: ${data.error}`);
checkAndCorrectDiffPath(data);
} else if ( data.status === 'nopatch-yet' || data.status === 'nodiff' ) {
ubolog(`Diff updater: skip update of ${data.name} using ${data.patchPath}, reason: ${data.status}`);
ubolog(`Diff updater: skip update of ${data.name} using ${data.patchPath}\n\treason: ${data.status}`);
const assetKey = assetKeyFromDiffName(data.name);
assetCacheSetDetails(assetKey, {
writeTime: data.lastModified || 0