Bug 602624 - Update local timestamp/signature only on success
authorEdward Lee <edilee@mozilla.com>
Thu, 07 Oct 2010 16:22:32 -0700
changeset 13 b94b31f857819fe8b1dd0b995df5ea54a6b1a7f6
parent 12 f1322c6a369ad761e01bd976349771902f93f608
child 14 9b95e7f5afcff6487d6a2d2b5d541caaeb324ec6
push id14
push useredward.lee@engineering.uiuc.edu
push dateThu, 07 Oct 2010 23:22:46 +0000
bugs602624
Bug 602624 - Update local timestamp/signature only on success Move various pref updates to the end of checkForUpdates().
bootstrap.js
--- a/bootstrap.js
+++ b/bootstrap.js
@@ -336,19 +336,16 @@ function checkForUpdates() {
       return;
     }
   }
   catch(ex) {
     Cu.reportError("Sigma signature check failure: '" + signature + "' " + ex);
     return;
   }
 
-  // Save the signature only on success
-  prefs.set("signature", signature);
-
   // Unpack the data now that we know it's from Mozilla
   let {infoUrl, install, timestamp, uninstall} = manifest.obj;
 
   // Make sure the manifest includes the time it was created
   let newTime = new Date(timestamp);
   if (isNaN(newTime)) {
     Cu.reportError("Sigma timestamp missing!");
     return;
@@ -360,30 +357,25 @@ function checkForUpdates() {
   }
 
   // Make sure this new manifest has a newer timestamp
   let oldTime = new Date(prefs.get("timestamp", 0));
   if (newTime <= oldTime) {
     Cu.reportError("Sigma timestamp misordering!");
     return;
   }
-  prefs.set("timestamp", timestamp);
 
   // Only open the info page if it's different
   let oldInfo = prefs.get("infoUrl");
   if (infoUrl != oldInfo) {
     prefs.set("infoUrl", infoUrl);
     let browser = Services.wm.getMostRecentWindow("navigator:browser").gBrowser;
     browser.selectedTab = browser.addTab(infoUrl);
   }
 
-  // Save the list of install add-on ids from the manifest
-  let installIds = install.map(function({id}) id);
-  prefs.set("installIds", JSON.stringify(installIds));
-
   // Install each listed add-on if necessary
   install.forEach(function({hash, id, url, version}) {
     AddonManager.getAddonByID(id, function(addon) {
       // Don't install if it's locally installed or newer
       if (addon != null && Svc.Version.compare(addon.version, version) >= 0)
         return;
 
       // Make sure we have a valid hash algorithm with hex output
@@ -404,16 +396,22 @@ function checkForUpdates() {
   // Uninstall each listed add-on id
   uninstall.forEach(function(id) {
     AddonManager.getAddonByID(id, function(addon) {
       if (addon == null)
         return;
       addon.uninstall();
     });
   });
+
+  // Save the various values from the current manifest now everything succeeded
+  let installIds = install.map(function({id}) id);
+  prefs.set("installIds", JSON.stringify(installIds));
+  prefs.set("signature", signature);
+  prefs.set("timestamp", timestamp);
 }
 
 /**
  * Watch for add-on manager updating add-ons to also check for updates
  */
 function observeAddonUpdates() {
   Cu.import("resource://gre/modules/AddonUpdateChecker.jsm");
   let orig = AddonUpdateChecker.checkForUpdates;