Fix
bug 601643 - Error during startup [NS_ERROR_FILE_ACCESS_DENIED in mozIStorageService.openSpecialDatabase() in calmgr_checkAndMigrateDB()]. r=mschroeder
--- a/calendar/base/src/calCalendarManager.js
+++ b/calendar/base/src/calCalendarManager.js
@@ -428,19 +428,19 @@ calCalendarManager.prototype = {
} finally {
selectPrefs.reset();
selectCalendars.reset();
}
},
checkAndMigrateDB: function calmgr_checkAndMigrateDB() {
- let dbService = Components.classes["@mozilla.org/storage/service;1"]
- .getService(Components.interfaces.mozIStorageService);
- db = dbService.openSpecialDatabase("profile");
+ let storageSdb = Services.dirsvc.get("ProfD", Components.interfaces.nsILocalFile);
+ storageSdb.append("storage.sdb");
+ db = Services.storage.openDatabase(storageSdb);
db.beginTransactionAs(Components.interfaces.mozIStorageConnection.TRANSACTION_EXCLUSIVE);
try {
if (db.tableExists("cal_calendars_prefs")) {
// Check if we need to upgrade:
let version = this.getSchemaVersion(db);
//cal.LOG("*** Calendar schema version is: " + version);
if (version < DB_SCHEMA_VERSION) {
--- a/calendar/providers/storage/calStorageCalendar.js
+++ b/calendar/providers/storage/calStorageCalendar.js
@@ -234,37 +234,37 @@ calStorageCalendar.prototype = {
return uri;
},
/**
* Initialize the Database. This should only be called from the uri or id
* setter and requires those two attributes to be set.
*/
prepareInitDB: function cSC_prepareInitDB() {
- let dbService = Components.classes["@mozilla.org/storage/service;1"]
- .getService(Components.interfaces.mozIStorageService);
if (this.uri.schemeIs("file")) {
let fileURL = this.uri.QueryInterface(Components.interfaces.nsIFileURL);
if (!fileURL)
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
// open the database
- this.mDB = dbService.openDatabase(fileURL.file);
+ this.mDB = Services.storage.openDatabase(fileURL.file);
upgradeDB(this.mDB);
} else if (this.uri.schemeIs("moz-profile-calendar")) {
// This is an old-style moz-profile-calendar. It requires some
// migration steps.
let localDB = cal.getCalendarDirectory();
localDB.append("local.sqlite");
- localDB = dbService.openDatabase(localDB);
+ localDB = Services.storage.openDatabase(localDB);
// First, we need to check if this is from 0.9, i.e we need to
// migrate from storage.sdb to local.sqlite.
- this.mDB = dbService.openSpecialDatabase("profile");
+ let storageSdb = Services.dirsvc.get("ProfD", Components.interfaces.nsILocalFile);
+ storageSdb.append("storage.sdb");
+ this.mDB = Services.storage.openDatabase(storageSdb);
if (this.mDB.tableExists("cal_events")) {
cal.LOG("Storage: Migrating storage.sdb -> local.sqlite");
upgradeDB(this.mDB); // upgrade schema before migating data
let attachStatement = createStatement(this.mDB, "ATTACH DATABASE :file_path AS local_sqlite");
try {
attachStatement.params.file_path = localDB.databaseFile.path;
attachStatement.execute();
} catch (exc) {
@@ -388,17 +388,17 @@ calStorageCalendar.prototype = {
this.logError("prepareInitDB moz-profile-calendar migration exception", exc);
this.mDB.rollbackTransaction();
throw exc;
}
} else if (this.uri.schemeIs("moz-storage-calendar")) {
// New style uri, no need for migration here
let localDB = cal.getCalendarDirectory();
localDB.append("local.sqlite");
- localDB = dbService.openDatabase(localDB);
+ localDB = Services.storage.openDatabase(localDB);
this.mDB = localDB;
upgradeDB(this.mDB);
}
this.initDB();
},