Bug 1226556 - part 3: add tableExists to ESEDBReader, use it to fall back to normal bookmarks migration, r=MattN

--HG--
extra : commitid : 9Ufl20lpqGu
extra : rebase_source : b416f9298c5b98538418918ee7263ca2e5c0e95f
extra : amend_source : 73cd202726de1c781c7ae2c84d94c9d89344d2d5
This commit is contained in:
Gijs Kruitbosch 2016-02-03 14:46:36 +00:00
Родитель 4393f911ee
Коммит 3475d4e50a
2 изменённых файлов: 61 добавлений и 7 удалений

Просмотреть файл

@ -312,7 +312,7 @@ ESEDB.prototype = {
checkForColumn(tableName, columnName) {
if (!this._opened) {
throw "The database was closed!";
throw new Error("The database was closed!");
}
let columnInfo;
@ -324,9 +324,33 @@ ESEDB.prototype = {
return columnInfo[0];
},
tableExists(tableName) {
if (!this._opened) {
throw new Error("The database was closed!");
}
let tableId = new ESE.JET_TABLEID();
let rv = ESE.ManualOpenTableW(this._sessionId, this._dbId, tableName, null,
0, 4 /* JET_bitTableReadOnly */,
tableId.address());
if (rv == -1305 /* JET_errObjectNotFound */) {
return false;
}
if (rv < 0) {
log.error("Got error " + rv + " calling OpenTableW");
throw new Error(convertESEError(rv));
}
if (rv > 0) {
log.error("Got warning " + rv + " calling OpenTableW");
}
ESE.FailSafeCloseTable(this._sessionId, tableId);
return true;
},
tableItems: function*(tableName, columns) {
if (!this._opened) {
throw "The database was closed!";
throw new Error("The database was closed!");
}
let tableOpened = false;
@ -391,7 +415,7 @@ ESEDB.prototype = {
let byteArray = ctypes.ArrayType(ctypes.uint8_t);
buffer = new byteArray(column.dbSize);
} else {
throw "Unknown type " + column.type;
throw new Error("Unknown type " + column.type);
}
return [buffer, buffer.constructor.size];
},
@ -403,7 +427,7 @@ ESEDB.prototype = {
buffer = null;
} else {
Cu.reportError("Unexpected JET error: " + err + ";" + " retrieving value for column " + column.name);
throw this.convertError(err);
throw new Error(convertESEError(err));
}
}
if (column.type == "string") {

Просмотреть файл

@ -227,8 +227,34 @@ function EdgeBookmarksMigrator() {
EdgeBookmarksMigrator.prototype = {
type: MigrationUtils.resourceTypes.BOOKMARKS,
get TABLE_NAME() { return "Favorites" },
get exists() {
return !!gEdgeDatabase;
if ("_exists" in this) {
return this._exists;
}
return this._exists = (!!gEdgeDatabase && this._checkTableExists());
},
_checkTableExists() {
let database;
let rv;
try {
let logFile = gEdgeDatabase.parent;
logFile.append("LogFiles");
database = ESEDBReader.openDB(gEdgeDatabase.parent, gEdgeDatabase, logFile);
rv = database.tableExists(this.TABLE_NAME);
} catch (ex) {
Cu.reportError("Failed to check for table " + tableName + " in Edge database at " +
gEdgeDatabase.path + " due to the following error: " + ex);
return false;
} finally {
if (database) {
ESEDBReader.closeDB(database);
}
}
return rv;
},
migrate(callback) {
@ -322,7 +348,7 @@ EdgeBookmarksMigrator.prototype = {
}
return true;
}
let bookmarks = readTableFromEdgeDB("Favorites", columns, filterFn);
let bookmarks = readTableFromEdgeDB(this.TABLE_NAME, columns, filterFn);
return {bookmarks, folderMap};
},
@ -367,8 +393,12 @@ function EdgeProfileMigrator() {
EdgeProfileMigrator.prototype = Object.create(MigratorPrototype);
EdgeProfileMigrator.prototype.getResources = function() {
let bookmarksMigrator = new EdgeBookmarksMigrator();
if (!bookmarksMigrator.exists) {
bookmarksMigrator = MSMigrationUtils.getBookmarksMigrator(MSMigrationUtils.MIGRATION_TYPE_EDGE);
}
let resources = [
new EdgeBookmarksMigrator(),
bookmarksMigrator,
MSMigrationUtils.getCookiesMigrator(MSMigrationUtils.MIGRATION_TYPE_EDGE),
new EdgeTypedURLMigrator(),
new EdgeReadingListMigrator(),