code to migrate obsolete list locations to new locations

This commit is contained in:
gorhill 2015-02-25 16:33:51 -05:00
parent 64d476472d
commit a9ce435f1c

View file

@ -134,6 +134,7 @@
µBlock.getAvailableLists = function(callback) { µBlock.getAvailableLists = function(callback) {
var availableLists = {}; var availableLists = {};
var relocationMap = {};
// selected lists // selected lists
var onSelectedListsLoaded = function(store) { var onSelectedListsLoaded = function(store) {
@ -143,11 +144,17 @@
var location, availableEntry, storedEntry; var location, availableEntry, storedEntry;
while ( location = locations.pop() ) { while ( location = locations.pop() ) {
storedEntry = lists[location];
// New location?
if ( relocationMap.hasOwnProperty(location) ) {
µb.purgeFilterList(location);
location = relocationMap[location];
}
availableEntry = availableLists[location]; availableEntry = availableLists[location];
if ( availableEntry === undefined ) { if ( availableEntry === undefined ) {
µb.purgeFilterList(location);
continue; continue;
} }
storedEntry = lists[location];
availableEntry.off = storedEntry.off || false; availableEntry.off = storedEntry.off || false;
µb.assets.setHomeURL(location, availableEntry.homeURL); µb.assets.setHomeURL(location, availableEntry.homeURL);
if ( storedEntry.entryCount !== undefined ) { if ( storedEntry.entryCount !== undefined ) {
@ -183,6 +190,13 @@
if ( /^https?:/.test(location) === false ) { if ( /^https?:/.test(location) === false ) {
location = 'assets/thirdparties/' + location; location = 'assets/thirdparties/' + location;
} }
// Migrate obsolete location to new location, if any
if ( typeof entry.oldLocation === 'string' ) {
if ( /^https?:/.test(entry.oldLocation) === false ) {
entry.oldLocation = 'assets/thirdparties/' + entry.oldLocation;
}
relocationMap[entry.oldLocation] = location;
}
availableLists[location] = entry; availableLists[location] = entry;
} }
@ -370,6 +384,13 @@
/******************************************************************************/ /******************************************************************************/
µBlock.purgeFilterList = function(path) {
this.purgeCompiledFilterList(path);
this.assets.purge(path);
};
/******************************************************************************/
µBlock.compileFilters = function(rawText) { µBlock.compileFilters = function(rawText) {
var rawEnd = rawText.length; var rawEnd = rawText.length;
var compiledFilters = []; var compiledFilters = [];