From 8c9acf2311cc6c1a8c255adf5de22d7407d8e52a Mon Sep 17 00:00:00 2001 From: "ben%bengoodger.com" Date: Wed, 8 Jun 2005 21:13:43 +0000 Subject: [PATCH] Fix the |selectUpdate| function on the update service to correctly return the best available update from a set of available updates --- toolkit/mozapps/update/content/updates.js | 4 ++++ .../mozapps/update/src/nsUpdateService.js.in | 19 +++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/toolkit/mozapps/update/content/updates.js b/toolkit/mozapps/update/content/updates.js index 75f4f8086660..1d69b74e2784 100755 --- a/toolkit/mozapps/update/content/updates.js +++ b/toolkit/mozapps/update/content/updates.js @@ -75,6 +75,10 @@ var gCheckingPage = { var aus = Components.classes["@mozilla.org/updates/update-service;1"] .getService(Components.interfaces.nsIApplicationUpdateService); gUpdates.update = aus.selectUpdate(updates, updates.length); + if (!gUpdates.update) { + LOG("Could not select an appropriate update, either because there were none," + + " or |selectUpdate| failed."); + } document.documentElement.advance(); }, diff --git a/toolkit/mozapps/update/src/nsUpdateService.js.in b/toolkit/mozapps/update/src/nsUpdateService.js.in index 67e583eb9c15..82ededc43d55 100644 --- a/toolkit/mozapps/update/src/nsUpdateService.js.in +++ b/toolkit/mozapps/update/src/nsUpdateService.js.in @@ -118,7 +118,7 @@ function getURLSpecFromFile(file) { } /** - * Gets the specified directory at the speciifed hierarchy under a + * Gets the specified directory at the specified hierarchy under a * Directory Service key. * @param key * The Directory Service Key to start from @@ -465,27 +465,26 @@ UpdateService.prototype = { * An array of available updates */ selectUpdate: function(updates) { - if (updates.length == 0) { - // XXXben erk + if (updates.length == 0) return null; - } // Choose the newest of the available minor and major updates. + var majorUpdate = null, minorUpdate = null; var newestMinor = updates[0], newestMajor = updates[0]; var vc = new VersionChecker(); for (var i = 0; i < updates.length; ++i) { if (updates[i].type == "major" && - vc.compare(updates[i].version, newestMajor.version) < 0) - newestMajor = updates[i]; - else if (updates[i].type == "minor" && - vc.compare(updates[i].version, newestMinor.version) < 0) - newestMinor = updates[i]; + vc.compare(newestMajor.version, updates[i].version) < 0) + majorUpdate = newestMajor = updates[i]; + if (updates[i].type == "minor" && + vc.compare(newestMinor.version, updates[i].version) < 0) + minorUpdate = newestMinor = updates[i]; } // If there's a major update, always try and fetch that one first, // otherwise fall back to the newest minor update. - return newestMajor || newestMinor; + return majorUpdate || minorUpdate; }, /**