1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-06 09:37:12 +02:00

harden just a bit more the migration code

This commit is contained in:
gorhill 2017-08-22 08:00:46 -04:00
parent c9a5b4c6ac
commit 06f9ac033f
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -27,21 +27,26 @@
(function() {
let µb = µBlock;
let migratedKeys = new Set();
let migrateAll = function(callback) {
let mustRestart = false;
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 = {};
bin[details.key] = JSON.parse(details.value);
self.browser.storage.local.set(bin, callback);
mustRestart = true;
};
let migrateNext = function() {
self.browser.runtime.sendMessage({ what: 'webext:storageMigrateNext' }, response => {
if ( response.key === undefined ) {
if ( mustRestart ) {
if ( migratedKeys.size !== 0 ) {
self.browser.runtime.reload();
} else {
callback();