Backed out changeset 7ac40f983b13 (bug 1386224) to fix the WNP regression r=rstrong a=me
authorSylvestre Ledru <sledru@mozilla.com>
Wed, 09 Aug 2017 09:12:59 +0200
changeset 414519 d8a11d7e960e24252a58c3d705fc525322ff58cc
parent 414518 4502ca8f2f51835179d2462e290a798ae2f39656
child 414520 3adc9de7f0de0f235eeb3c9f047a2076bd49a2f8
push id1498
push usersledru@mozilla.com
push dateWed, 09 Aug 2017 07:13:50 +0000
treeherdermozilla-release@d8a11d7e960e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrstrong, me
bugs1386224
milestone55.0.1
backs out7ac40f983b139d8252dea5091e3790996ed04990
Backed out changeset 7ac40f983b13 (bug 1386224) to fix the WNP regression r=rstrong a=me
toolkit/mozapps/update/nsUpdateService.js
toolkit/mozapps/update/tests/unit_base_updater/marAppApplyUpdateStageOldVersionFailure.js
--- a/toolkit/mozapps/update/nsUpdateService.js
+++ b/toolkit/mozapps/update/nsUpdateService.js
@@ -1597,19 +1597,23 @@ UpdateService.prototype = {
    *          The notification name
    * @param   data
    *          Additional data
    */
   observe: function AUS_observe(subject, topic, data) {
     switch (topic) {
       case "post-update-processing":
         if (readStatusFile(getUpdatesDir()) == STATE_SUCCEEDED) {
-          // After a successful update the post update preference needs to be
-          // set early during startup so applications can perform post update
-          // actions when they are defined in the update's metadata.
+          // The active update needs to be copied to the first update in the
+          // updates.xml early during startup to support post update actions
+          // (bug 1301288).
+          let um = Cc["@mozilla.org/updates/update-manager;1"].
+                   getService(Ci.nsIUpdateManager);
+          um.activeUpdate.state = STATE_SUCCEEDED;
+          um.saveUpdates();
           Services.prefs.setBoolPref(PREF_APP_UPDATE_POSTUPDATE, true);
         }
 
         if (Services.appinfo.ID in APPID_TO_TOPIC) {
           // Delay post-update processing to ensure that possible update
           // dialogs are shown in front of the app window, if possible.
           // See bug 311614.
           Services.obs.addObserver(this, APPID_TO_TOPIC[Services.appinfo.ID]);
@@ -2644,30 +2648,33 @@ UpdateManager.prototype = {
    * replace the existing value with the new value.
    * @param   update
    *          The nsIUpdate object to add.
    */
   _addUpdate: function UM__addUpdate(update) {
     if (!update)
       return;
     this._ensureUpdates();
-    // Only the latest update entry is checked so the the latest successful
-    // step for an update is recorded and all failures are kept. This way
-    // mutliple attempts to update for the same update are kept in the update
-    // history.
-    if (this._updates &&
-        update.state != STATE_FAILED &&
-        this._updates[0] &&
-        this._updates[0].state != STATE_FAILED &&
-        this._updates[0].appVersion == update.appVersion &&
-        this._updates[0].buildID == update.buildID) {
-      // Replace the existing entry with the new value, updating
-      // all metadata.
-      this._updates[0] = update;
-      return;
+    if (this._updates) {
+      for (var i = 0; i < this._updates.length; ++i) {
+        // Keep all update entries with a state of STATE_FAILED and replace the
+        // first update entry that has the same application version and build ID
+        // if it exists. This allows the update history to only have one success
+        // entry for an update and entries for all failed updates.
+        if (update.state != STATE_FAILED &&
+            this._updates[i] &&
+            this._updates[i].state != STATE_FAILED &&
+            this._updates[i].appVersion == update.appVersion &&
+            this._updates[i].buildID == update.buildID) {
+          // Replace the existing entry with the new value, updating
+          // all metadata.
+          this._updates[i] = update;
+          return;
+        }
+      }
     }
     // Otherwise add it to the front of the list.
     this._updates.unshift(update);
   },
 
   /**
    * Serializes an array of updates to an XML file
    * @param   updates
@@ -2713,22 +2720,25 @@ UpdateManager.prototype = {
    */
   saveUpdates: function UM_saveUpdates() {
     this._writeUpdatesToXMLFile([this._activeUpdate],
                                 getUpdateFile([FILE_ACTIVE_UPDATE_XML]));
     if (this._activeUpdate)
       this._addUpdate(this._activeUpdate);
 
     this._ensureUpdates();
-    // Don't write updates that don't have a state to the updates.xml file.
+    // Don't write updates that have a temporary state to the updates.xml file.
     if (this._updates) {
       let updates = this._updates.slice();
       for (let i = updates.length - 1; i >= 0; --i) {
         let state = updates[i].state;
-        if (state == STATE_NONE) {
+        if (state == STATE_NONE || state == STATE_DOWNLOADING ||
+            state == STATE_APPLIED || state == STATE_APPLIED_SERVICE ||
+            state == STATE_PENDING || state == STATE_PENDING_SERVICE ||
+            state == STATE_PENDING_ELEVATE) {
           updates.splice(i, 1);
         }
       }
 
       this._writeUpdatesToXMLFile(updates.slice(0, 20),
                                   getUpdateFile([FILE_UPDATES_XML]));
     }
   },
--- a/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyUpdateStageOldVersionFailure.js
+++ b/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyUpdateStageOldVersionFailure.js
@@ -55,17 +55,17 @@ function stageUpdateFinished() {
  * Called after the call to runUpdateUsingApp finishes.
  */
 function runUpdateFinished() {
   standardInit();
   Assert.equal(readStatusState(), STATE_NONE,
                "the status file state" + MSG_SHOULD_EQUAL);
   Assert.ok(!gUpdateManager.activeUpdate,
             "the active update should not be defined");
-  Assert.equal(gUpdateManager.updateCount, 2,
+  Assert.equal(gUpdateManager.updateCount, 1,
                "the update manager updateCount attribute" + MSG_SHOULD_EQUAL);
   Assert.equal(gUpdateManager.getUpdateAt(0).state, STATE_AFTER_STAGE,
                "the update state" + MSG_SHOULD_EQUAL);
   checkPostUpdateRunningFile(false);
   setTestFilesAndDirsForFailure();
   checkFilesAfterUpdateFailure(getApplyDirFile, IS_MACOSX ? false : true, false);
 
   let updatesDir = getUpdatesPatchDir();