diff --git a/lib/meteor.js b/lib/meteor.js index fcacd7bae5..0fdd3f679c 100644 --- a/lib/meteor.js +++ b/lib/meteor.js @@ -370,7 +370,8 @@ Fiber(function () { process.exit(1); } - require(path.join(__dirname, 'update.js')); + var update = require(path.join(__dirname, 'update.js')); + update.updateMeteor(); } }); diff --git a/lib/run.js b/lib/run.js index c415ad7ad7..b98661d38a 100644 --- a/lib/run.js +++ b/lib/run.js @@ -497,20 +497,25 @@ _.extend(DependencyWatcher.prototype, { // XXX this should move to main meteor command-line, probably? var start_update_checks = function () { var update_check = function () { - updater.get_manifest(function (manifest) { - if (!files.in_checkout() && manifest && - updater.needs_upgrade(manifest)) { - console.log("////////////////////////////////////////"); - console.log("////////////////////////////////////////"); - console.log(); - console.log("meteor is out of date. Please run:"); - console.log(); - console.log(" meteor update"); - console.log(); - console.log("////////////////////////////////////////"); - console.log("////////////////////////////////////////"); - } - }); + // XXX update for engine + try { + var manifest = updater.getManifest(); + } catch (e) { + // Ignore errors (eg, offline) + return; + } + if (!files.in_checkout() && manifest && + updater.needs_upgrade(manifest)) { + console.log("////////////////////////////////////////"); + console.log("////////////////////////////////////////"); + console.log(); + console.log("meteor is out of date. Please run:"); + console.log(); + console.log(" meteor update"); + console.log(); + console.log("////////////////////////////////////////"); + console.log("////////////////////////////////////////"); + } }; setInterval(update_check, 12*60*60*1000); // twice a day update_check(); // and now. diff --git a/lib/update.js b/lib/update.js index 6106874b73..175d74e78c 100644 --- a/lib/update.js +++ b/lib/update.js @@ -19,8 +19,11 @@ if (files.in_checkout()) { process.exit(1); } -// Immediately kick off manifest check. -updater.get_manifest(function (manifest) { +// XXX update for engine +var updateMeteor = function () { + // Immediately kick off manifest check. + // XXX error check + var manifest = updater.getManifest(); //// Examine manifest and see if we need to upgrade. @@ -248,4 +251,4 @@ updater.get_manifest(function (manifest) { }); req.end(); -}); +}; diff --git a/lib/updater.js b/lib/updater.js index 74b74ea7fe..7b647365b1 100644 --- a/lib/updater.js +++ b/lib/updater.js @@ -9,52 +9,21 @@ var http = require("http"); var https = require("https"); var path = require("path"); var semver = require("semver"); +var Future = require('fibers/future'); var files = require(path.join(__dirname, 'files.js')); -var manifest_options = testingUpdater ? { - host: 's3.amazonaws.com', - path: '/com.meteor.static/test/update/manifest.json' -} : { - host: 'update.meteor.com', - path: '/manifest.json' -}; +var manifestUrl = testingUpdater + ? 'https://s3.amazonaws.com/com.meteor.static/test/update/manifest.json' + : 'https://update.meteor.com/manifest.json'; /** * Downloads the current manifest file and returns it via a callback (or * null on error) */ -// XXX make this synchronous -exports.get_manifest = function (callback) { - // XXX this is gross. use files.getUrl instead. - var req = https.request(manifest_options, function(res) { - if (res.statusCode !== 200) { - callback(null); - return; - } - res.setEncoding('utf8'); - var manifest = ''; - res.on('data', function (chunk) { - manifest = manifest + chunk; - }); - res.on('end', function () { - var parsed; - try { - parsed = JSON.parse(manifest); - } catch (err) { - parsed = null; - }; - callback(parsed); - }); - }); - req.addListener('error', function (err) { - // Need to register an error handler or node will crash: - // http://rentzsch.tumblr.com/post/664884799/node-js-handling-refused-http-client-connections - - callback(null); - }); - req.end(); +exports.getManifest = function () { + return Future.wrap(files.getUrl)({url: manifestUrl, json: true}); }; /** diff --git a/lib/warehouse.js b/lib/warehouse.js index bf0936ba84..d7fad1105b 100644 --- a/lib/warehouse.js +++ b/lib/warehouse.js @@ -95,7 +95,7 @@ var warehouse = module.exports = { // XXX make errors prettier fetchLatestRelease: function () { - var manifest = Future.wrap(updater.get_manifest)().wait(); + var manifest = updater.getManifest(); // XXX in the future support release channels other than stable var releaseName = manifest.releases.stable; if (!releaseName) {