Skip to content

Commit

Permalink
Merge pull request #297 from prey/upgrade-fixes
Browse files Browse the repository at this point in the history
Upgrade download fixes
  • Loading branch information
javo authored May 4, 2017
2 parents e33a712 + d37e149 commit 6e94a76
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,25 +335,25 @@ package.get_latest = function(branch, current_version, dest, cb) {
if (err || !version)
return cb(err || new Error('Already running latest version.'));

package.check_upgrade(version, dest, function(err) {
package.get_version(version, dest, function(err) {
cb(err, version);
});
});
};

// called from lib/conf/install when a specific version is passed, e.g. 'config upgrade 1.2.3'
package.check_upgrade = function(version, dest, cb) {
package.get_version = function(version, dest, cb) {
var keys = require('./agent/plugins/control-panel/api/keys'),
shared = require('./conf/shared');

if (process.argv.indexOf('test') != -1) return package.get_version(version, dest, cb)
if (process.argv.indexOf('test') != -1) return package.download_install(version, dest, cb)
shared.keys.verify_current(function(err) {
if (err) return cb(new Error("Missing user credencials, update cancelled for now"));

update_attempts(version, function(err, update) {
if (err) return cb(err);
if (update) {
package.get_version(version, dest, function(err) {
package.download_install(version, dest, function(err) {
cb(err, version);
});
} else {
Expand All @@ -363,7 +363,7 @@ package.check_upgrade = function(version, dest, cb) {
});
}

package.get_version = function(version, dest, cb) {
package.download_install = function(version, dest, cb) {

var final_path = path.join(dest, version);
if (fs.existsSync(final_path))
Expand All @@ -374,9 +374,7 @@ package.get_version = function(version, dest, cb) {
if (err) return cb(err);

package.install(file, dest, function(err, installed_version) {
fs.unlink(file, function() {
cb(err, installed_version);
})
cb(err, installed_version);
});
});
}
Expand Down

0 comments on commit 6e94a76

Please sign in to comment.