mirror of https://github.com/gorhill/uBlock.git
harden just a bit more the migration code
This commit is contained in:
parent
c9a5b4c6ac
commit
06f9ac033f
|
@ -27,21 +27,26 @@
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
let µb = µBlock;
|
let µb = µBlock;
|
||||||
|
let migratedKeys = new Set();
|
||||||
|
|
||||||
let migrateAll = function(callback) {
|
let migrateAll = function(callback) {
|
||||||
let mustRestart = false;
|
|
||||||
|
|
||||||
let migrateKeyValue = function(details, callback) {
|
let migrateKeyValue = function(details, callback) {
|
||||||
|
// https://github.com/gorhill/uBlock/issues/2653
|
||||||
|
// Be ready to deal graciously with corrupted DB.
|
||||||
|
if ( migratedKeys.has(details.key) ) {
|
||||||
|
callback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
migratedKeys.add(details.key);
|
||||||
let bin = {};
|
let bin = {};
|
||||||
bin[details.key] = JSON.parse(details.value);
|
bin[details.key] = JSON.parse(details.value);
|
||||||
self.browser.storage.local.set(bin, callback);
|
self.browser.storage.local.set(bin, callback);
|
||||||
mustRestart = true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let migrateNext = function() {
|
let migrateNext = function() {
|
||||||
self.browser.runtime.sendMessage({ what: 'webext:storageMigrateNext' }, response => {
|
self.browser.runtime.sendMessage({ what: 'webext:storageMigrateNext' }, response => {
|
||||||
if ( response.key === undefined ) {
|
if ( response.key === undefined ) {
|
||||||
if ( mustRestart ) {
|
if ( migratedKeys.size !== 0 ) {
|
||||||
self.browser.runtime.reload();
|
self.browser.runtime.reload();
|
||||||
} else {
|
} else {
|
||||||
callback();
|
callback();
|
||||||
|
|
Loading…
Reference in New Issue