mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 887868 - Remove migration from old Search Service DB. r=gavin
This commit is contained in:
parent
a3d913c879
commit
eb67e8a1a6
@ -3739,8 +3739,6 @@ var engineMetadataService = {
|
||||
_InitStates: {
|
||||
NOT_STARTED: "NOT_STARTED"
|
||||
/**Initialization has not started*/,
|
||||
JSON_LOADING_ATTEMPTED: "JSON_LOADING_ATTEMPTED"
|
||||
/**JSON file was loaded or does not exist*/,
|
||||
FINISHED_SUCCESS: "FINISHED_SUCCESS"
|
||||
/**Setup complete, with a success*/
|
||||
},
|
||||
@ -3777,60 +3775,23 @@ var engineMetadataService = {
|
||||
return;
|
||||
}
|
||||
this._store = JSON.parse(new TextDecoder().decode(contents));
|
||||
this._initState = engineMetadataService._InitStates.FINISHED_SUCCESS;
|
||||
return;
|
||||
} catch (ex) {
|
||||
if (this._initState == engineMetadataService._InitStates.FINISHED_SUCCESS) {
|
||||
// No need to pursue asynchronous initialization,
|
||||
// synchronous fallback was called and has finished.
|
||||
return;
|
||||
}
|
||||
if (ex.becauseNoSuchFile) {
|
||||
// If the file does not exist, we need to continue initialization
|
||||
this._initState = engineMetadataService._InitStates.JSON_LOADING_ATTEMPTED;
|
||||
} else {
|
||||
// Otherwise, we are done
|
||||
LOG("metadata init: could not load JSON file " + ex);
|
||||
this._store = {};
|
||||
this._initState = engineMetadataService._InitStates.FINISHED_SUCCESS;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Fall through to the next state
|
||||
|
||||
case engineMetadataService._InitStates.JSON_LOADING_ATTEMPTED:
|
||||
// 2. Otherwise, load db
|
||||
try {
|
||||
let store = yield this._asyncMigrateOldDB();
|
||||
if (this._initState == engineMetadataService._InitStates.FINISHED_SUCCESS) {
|
||||
// No need to pursue asynchronous initialization,
|
||||
// synchronous fallback was called and has finished.
|
||||
return;
|
||||
}
|
||||
if (!store) {
|
||||
LOG("metadata init: No store to migrate to disk");
|
||||
this._store = {};
|
||||
} else {
|
||||
// Commit the migrated store to disk immediately
|
||||
LOG("metadata init: Committing the migrated store to disk");
|
||||
this._store = store;
|
||||
this._commit(store);
|
||||
}
|
||||
} catch (ex) {
|
||||
if (this._initState == engineMetadataService._InitStates.FINISHED_SUCCESS) {
|
||||
// No need to pursue asynchronous initialization,
|
||||
// synchronous fallback was called and has finished.
|
||||
return;
|
||||
}
|
||||
LOG("metadata init: Error migrating store, using an empty store: " + ex);
|
||||
// Couldn't load json, use an empty store
|
||||
LOG("metadata init: could not load JSON file " + ex);
|
||||
this._store = {};
|
||||
}
|
||||
this._initState = engineMetadataService._InitStates.FINISHED_SUCCESS;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Error("metadata init: invalid state " + this._initState);
|
||||
}
|
||||
|
||||
this._initState = this._InitStates.FINISHED_SUCCESS;
|
||||
LOG("metadata init: complete");
|
||||
}).bind(this)).then(
|
||||
// 3. Inform any observers
|
||||
@ -3868,30 +3829,12 @@ var engineMetadataService = {
|
||||
LOG("metadata syncInit: could not load JSON file " + x);
|
||||
this._store = {};
|
||||
}
|
||||
this._initState = this._InitStates.FINISHED_SUCCESS;
|
||||
break;
|
||||
}
|
||||
this._initState = this._InitStates.JSON_LOADING_ATTEMPTED;
|
||||
// Fall through to the next state
|
||||
|
||||
case engineMetadataService._InitStates.JSON_LOADING_ATTEMPTED:
|
||||
// 2. No json, attempt to migrate from a database
|
||||
try {
|
||||
let store = this._syncMigrateOldDB();
|
||||
if (!store) {
|
||||
LOG("metadata syncInit: No store to migrate to disk");
|
||||
this._store = {};
|
||||
} else {
|
||||
// Commit the migrated store to disk immediately
|
||||
LOG("metadata syncInit: Committing the migrated store to disk");
|
||||
this._store = store;
|
||||
this._commit(store);
|
||||
}
|
||||
} catch (ex) {
|
||||
LOG("metadata syncInit: Error migrating store, using an empty store: " + ex);
|
||||
} else {
|
||||
LOG("metadata syncInit: using an empty store");
|
||||
this._store = {};
|
||||
}
|
||||
this._initState = engineMetadataService._InitStates.FINISHED_SUCCESS;
|
||||
|
||||
this._initState = this._InitStates.FINISHED_SUCCESS;
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -3983,84 +3926,6 @@ var engineMetadataService = {
|
||||
}
|
||||
},
|
||||
|
||||
_syncMigrateOldDB: function SRCH_SVC_EMS_migrate() {
|
||||
let sqliteFile = FileUtils.getFile(NS_APP_USER_PROFILE_50_DIR,
|
||||
["search.sqlite"]);
|
||||
if (!sqliteFile.exists()) {
|
||||
LOG("metadata _syncMigrateOldDB: search.sqlite does not exist");
|
||||
return null;
|
||||
}
|
||||
let store = {};
|
||||
try {
|
||||
LOG("metadata _syncMigrateOldDB: Migrating data from SQL");
|
||||
const sqliteDb = Services.storage.openDatabase(sqliteFile);
|
||||
const statement = sqliteDb.createStatement("SELECT * from engine_data");
|
||||
while (statement.executeStep()) {
|
||||
let row = statement.row;
|
||||
let engine = row.engineid;
|
||||
let name = row.name;
|
||||
let value = row.value;
|
||||
if (!store[engine]) {
|
||||
store[engine] = {};
|
||||
}
|
||||
store[engine][name] = value;
|
||||
}
|
||||
statement.finalize();
|
||||
sqliteDb.close();
|
||||
} catch (ex) {
|
||||
LOG("metadata _syncMigrateOldDB failed: " + ex);
|
||||
return null;
|
||||
}
|
||||
return store;
|
||||
},
|
||||
|
||||
/**
|
||||
* Migrate search.sqlite, asynchronously
|
||||
*
|
||||
* Notes:
|
||||
* - we do not remove search.sqlite after migration, so as to allow
|
||||
* downgrading and forensics;
|
||||
*/
|
||||
_asyncMigrateOldDB: function SRCH_SVC_EMS_asyncMigrate() {
|
||||
return TaskUtils.spawn(function task() {
|
||||
let sqliteFile = FileUtils.getFile(NS_APP_USER_PROFILE_50_DIR, ["search.sqlite"]);
|
||||
if (!(yield OS.File.exists(sqliteFile.path))) {
|
||||
LOG("metadata _asyncMigrateOldDB: search.sqlite does not exist");
|
||||
throw new Task.Result(); // Bail out
|
||||
}
|
||||
LOG("metadata _asyncMigrateOldDB: Migrating data from SQL");
|
||||
let store = {};
|
||||
const sqliteDb = Services.storage.openDatabase(sqliteFile);
|
||||
const statement = sqliteDb.createStatement("SELECT * from engine_data");
|
||||
try {
|
||||
yield TaskUtils.executeStatement(
|
||||
statement,
|
||||
function onResult(aResultSet) {
|
||||
while (true) {
|
||||
let row = aResultSet.getNextRow();
|
||||
if (!row) {
|
||||
break;
|
||||
}
|
||||
let engine = row.engineid;
|
||||
let name = row.name;
|
||||
let value = row.value;
|
||||
if (!store[engine]) {
|
||||
store[engine] = {};
|
||||
}
|
||||
store[engine][name] = value;
|
||||
}
|
||||
}
|
||||
);
|
||||
} catch (ex) {
|
||||
// If loading the db failed, ignore the db
|
||||
throw new Task.Result(); // Bail out
|
||||
} finally {
|
||||
sqliteDb.asyncClose();
|
||||
}
|
||||
throw new Task.Result(store);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Commit changes to disk, asynchronously.
|
||||
*
|
||||
|
@ -1,39 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
/*
|
||||
* test_migratedb: Start search engine
|
||||
* - without search-metadata.json
|
||||
* - with search.sqlite
|
||||
*
|
||||
* Ensure that nothing explodes.
|
||||
*/
|
||||
|
||||
function run_test()
|
||||
{
|
||||
removeMetadata();
|
||||
|
||||
updateAppInfo();
|
||||
|
||||
let search_sqlite = do_get_file("data/search.sqlite");
|
||||
search_sqlite.copyTo(gProfD, "search.sqlite");
|
||||
|
||||
let search = Services.search;
|
||||
|
||||
do_test_pending();
|
||||
|
||||
afterCommit(function commit_complete() {
|
||||
// Check that search-metadata.json has been created
|
||||
let metadata = gProfD.clone();
|
||||
metadata.append("search-metadata.json");
|
||||
do_check_true(metadata.exists());
|
||||
|
||||
removeMetadata();
|
||||
do_test_finished();
|
||||
});
|
||||
|
||||
search.init(function ss_initialized(rv) {
|
||||
do_check_true(Components.isSuccessCode(rv));
|
||||
search.getEngines();
|
||||
});
|
||||
}
|
@ -11,7 +11,6 @@ skip-if = debug && os == "linux"
|
||||
[test_init_async_multiple.js]
|
||||
[test_init_async_multiple_then_sync.js]
|
||||
[test_json_cache.js]
|
||||
[test_migratedb.js]
|
||||
[test_nodb.js]
|
||||
[test_nodb_pluschanges.js]
|
||||
[test_save_sorted_engines.js]
|
||||
|
Loading…
Reference in New Issue
Block a user