Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var activate = require('./lib/activate');
var download = require('./lib/download');
var extract = require('./lib/extract');
var debug = require('debug')('mongodb-version-manager');
var os = require('os');

var VERSION = /[0-9]+\.[0-9]+\.[0-9]+([-_\.][a-zA-Z0-9]+)?/;

Expand All @@ -20,7 +21,11 @@ var bin = path.join(path.current({
}), 'bin');

if (process.env.PATH.indexOf(bin) === -1) {
process.env.PATH = bin + ':' + process.env.PATH;
if (os.platform() === 'win32') {
process.env.PATH = bin + ';' + process.env.PATH;
} else {
process.env.PATH = bin + ':' + process.env.PATH;
}
}

module.exports = function(opts, fn) {
Expand Down
7 changes: 6 additions & 1 deletion lib/activate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ var debug = require('debug')('mvm:activate');
var path = require('./path');
var fs = require('fs-extra');
var tildify = require('tildify');
var os = require('os');

module.exports = function(pkg, fn) {
var bin = path.resolve(path.current(pkg) + '/bin');

if (process.env.PATH.indexOf(bin) === -1) {
process.env.PATH = bin + ':' + process.env.PATH;
if (os.platform() === 'win32') {
process.env.PATH = bin + ';' + process.env.PATH;
} else {
process.env.PATH = bin + ':' + process.env.PATH;
}
debug('added to PATH %s', tildify(bin));
}

Expand Down
30 changes: 15 additions & 15 deletions lib/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var unzip = require('unzip');
var tar = require('tar');
var createCleanupCrew = require('./cleanup');
var path = require('./path');
var nodePath = require('path');
var tildify = require('tildify');
var debug = require('debug')('mvm::extract');

Expand Down Expand Up @@ -35,6 +36,15 @@ module.exports = function extract(pkg, fn) {
path: dest
});
input.pipe(extractor);
extractor.on('close', function() {
debug('created %s', tildify(dest));
cleanup.clear();
var full = nodePath.join(dest, nodePath.basename(pkg.artifact, '.zip'));
fs.move(full, dest, function(err) {
if (err) return fn(err, null);
fn(null, dest);
});
});
} else {
var ungzip = zlib.createGunzip();
extractor = tar.Extract({
Expand All @@ -49,25 +59,15 @@ module.exports = function extract(pkg, fn) {

debug('untar-ing....');
ungzip.pipe(extractor);
extractor.on('end', function() {
debug('created %s', tildify(dest));
cleanup.clear();
fn(null, dest);
});
}

extractor.on('error', function(err) {
console.error(err);
});
var onClose;

var onEnd = function() {
debug('created %s', tildify(dest));
cleanup.clear();
extractor.removeListener('readable', onClose);
fn(null, dest);
};
onClose = function() {
debug('created %s', tildify(dest));
cleanup.clear();
extractor.removeListener('readable', onEnd);
fn(null, dest);
};
extractor.once('end', onEnd).once('close', onClose);
});
};