1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-07 03:12:33 +01:00

Harden compiled/selfie format change detection at launch

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/759

This commit adds code to rely less on the state of the
cache storage to decide whether filter lists should be
re-compiled or whether the selfie is currently valid
at launch time when a change in compiled/selfie format
is detected.
This commit is contained in:
Raymond Hill 2019-10-27 11:49:05 -04:00
parent b79445320d
commit d7b2d31180
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
3 changed files with 26 additions and 10 deletions

View File

@ -145,6 +145,16 @@ const µBlock = (( ) => { // jshint ignore:line
selfieMagic: 23, // Increase when selfie format changes
},
// https://github.com/uBlockOrigin/uBlock-issues/issues/759#issuecomment-546654501
// The assumption is that cache storage state reflects whether
// compiled or selfie assets are available or not. The properties
// below is to no longer rely on this assumption -- though it's still
// not clear how the assumption could be wrong, and it's still not
// clear whether relying on those properties will really solve the
// issue. It's just an attempt at hardening.
compiledFormatChanged: false,
selfieIsInvalid: false,
restoreBackupSettings: {
lastRestoreFile: '',
lastRestoreTime: 0,

View File

@ -173,15 +173,15 @@ const onUserSettingsReady = function(fetched) {
// Housekeeping, as per system setting changes
const onSystemSettingsReady = function(fetched) {
let mustSaveSystemSettings = false;
if ( fetched.compiledMagic !== µb.systemSettings.compiledMagic ) {
µb.assets.remove(/^compiled\//);
mustSaveSystemSettings = true;
µb.compiledFormatChanged = true;
µb.selfieIsInvalid = true;
}
if ( fetched.selfieMagic !== µb.systemSettings.selfieMagic ) {
mustSaveSystemSettings = true;
µb.selfieIsInvalid = true;
}
if ( mustSaveSystemSettings ) {
if ( µb.selfieIsInvalid ) {
fetched.selfie = null;
µb.selfieManager.destroy();
vAPI.storage.set(µb.systemSettings);

View File

@ -638,6 +638,7 @@
this.selfieManager.destroy();
this.lz4Codec.relinquish();
this.compiledFormatChanged = false;
loadingPromise = undefined;
};
@ -712,10 +713,12 @@
µBlock.getCompiledFilterList = async function(assetKey) {
const compiledPath = 'compiled/' + assetKey;
let compiledDetails = await this.assets.get(compiledPath);
if ( compiledDetails.content !== '' ) {
compiledDetails.assetKey = assetKey;
return compiledDetails;
if ( this.compiledFormatChanged === false ) {
let compiledDetails = await this.assets.get(compiledPath);
if ( compiledDetails.content !== '' ) {
compiledDetails.assetKey = assetKey;
return compiledDetails;
}
}
const rawDetails = await this.assets.get(assetKey);
@ -730,7 +733,7 @@
// Fetching the raw content may cause the compiled content to be
// generated somewhere else in uBO, hence we try one last time to
// fetch the compiled content in case it has become available.
compiledDetails = await this.assets.get(compiledPath);
let compiledDetails = await this.assets.get(compiledPath);
if ( compiledDetails.content === '' ) {
compiledDetails.content = this.compileFilters(
rawDetails.content,
@ -1053,6 +1056,7 @@
),
]);
µb.lz4Codec.relinquish();
µb.selfieIsInvalid = false;
};
const loadMain = async function() {
@ -1080,7 +1084,7 @@
};
const load = async function() {
if ( destroyTimer !== undefined ) {
if ( µb.selfieIsInvalid ) {
return false;
}
try {
@ -1108,6 +1112,7 @@
const destroy = function() {
µb.cacheStorage.remove('selfie'); // TODO: obsolete, remove eventually.
µb.assets.remove(/^selfie\//);
µb.selfieIsInvalid = true;
createTimer = vAPI.setTimeout(( ) => {
createTimer = undefined;
create();
@ -1127,6 +1132,7 @@
},
1019
);
µb.selfieIsInvalid = true;
};
return { load, destroy: destroyAsync };