Bug 1331477 - Part 2. Always close permissions db after an error during migration. r=IanN
authorFrank-Rainer Grahl <frgrahl@gmx.net>
Sat, 25 Feb 2017 12:34:34 +0100
changeset 24351 836c4adc56091868c7d52b34f772960e120e47b9
parent 24350 0dc9c80964b914640523c449ee0bd2cc286e4978
child 24352 4b1fc11b94209e7cf767f4805a0b774b209f7a98
push id2022
push userclokep@gmail.com
push dateTue, 07 Mar 2017 14:36:55 +0000
treeherdercomm-aurora@ecedf2f0d1b4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersIanN
bugs1331477
Bug 1331477 - Part 2. Always close permissions db after an error during migration. r=IanN
suite/common/src/nsSuiteGlue.js
--- a/suite/common/src/nsSuiteGlue.js
+++ b/suite/common/src/nsSuiteGlue.js
@@ -393,50 +393,50 @@ SuiteGlue.prototype = {
     // Migrate remote content exceptions for email addresses which are
     // encoded as chrome URIs.
     if (currentUIVersion < 1) {
       let permissionsDB =
         Services.dirsvc.get("ProfD", Components.interfaces.nsILocalFile);
       permissionsDB.append("permissions.sqlite");
       let db = Services.storage.openDatabase(permissionsDB);
 
-      let statement = db.createStatement(
-        "select origin, permission from moz_perms where " +
-        // Avoid 'like' here which needs to be escaped.
-        "  substr(origin, 1, 28) = 'chrome://messenger/content/?';");
+      try {
+        let statement = db.createStatement(
+          "select origin, permission from moz_perms where " +
+          // Avoid 'like' here which needs to be escaped.
+          "  substr(origin, 1, 28) = 'chrome://messenger/content/?';");
 
-      try {
-        while (statement.executeStep()) {
-          let origin = statement.getUTF8String(0);
-          let permission = statement.getInt32(1);
-          Services.console.logStringMessage("Mail-Image-Perm Mig: " + origin);
-          Services.perms.remove(
-            Services.io.newURI(origin), "image");
-          origin = origin.replace("chrome://messenger/content/?",
-                                  "chrome://messenger/content/");
-          Services.perms.add(
-            Services.io.newURI(origin), "image", permission);
+        try {
+          while (statement.executeStep()) {
+            let origin = statement.getUTF8String(0);
+            let permission = statement.getInt32(1);
+            Services.console.logStringMessage("Mail-Image-Perm Mig: " + origin);
+            Services.perms.remove(
+              Services.io.newURI(origin), "image");
+            origin = origin.replace("chrome://messenger/content/?",
+                                    "chrome://messenger/content/");
+            Services.perms.add(
+              Services.io.newURI(origin), "image", permission);
+          }
+        } finally {
+          statement.finalize();
         }
-      } catch (ex) {
-        throw ex;
-      } finally {
-        statement.finalize();
-      }
+
+        // Sadly we still need to clear the database manually. Experiments
+        // showed that the permissions manager deletes only one record.
+        db.beginTransactionAs(Components.interfaces.mozIStorageConnection.TRANSACTION_EXCLUSIVE);
 
-      // Sadly we still need to clear the database manually. Experiments
-      // showed that the permissions manager deletes only one record.
-      db.beginTransactionAs(Components.interfaces.mozIStorageConnection.TRANSACTION_EXCLUSIVE);
-
-      try {
-        db.executeSimpleSQL("delete from moz_perms where " +
-             "  substr(origin, 1, 28) = 'chrome://messenger/content/?';");
-        db.commitTransaction();
-      } catch (ex) {
-        db.rollbackTransaction();
-        throw ex;
+        try {
+          db.executeSimpleSQL("delete from moz_perms where " +
+               "  substr(origin, 1, 28) = 'chrome://messenger/content/?';");
+          db.commitTransaction();
+        } catch (ex) {
+          db.rollbackTransaction();
+          throw ex;
+        }
       } finally {
         db.close();
       }
     }
 
     // Update the migration version.
     Services.prefs.setIntPref("suite.migration.version", UI_VERSION);
   },