Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
using vanilla step again with some .bind() tricks for err stuff
  • Loading branch information
James Halliday committed Oct 10, 2010
1 parent 9198573 commit 31c3eba
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions lib/models/setup.js
Expand Up @@ -3,37 +3,39 @@ var sys = require('sys');
var fs = require('fs');
var path = require('path');

var Hash = require('traverse/hash');
var Step = require('step');

exports.deploy = function (dir, opts, cb) {
var self = this;
console.log('Deploying StackVM to ' + dir);
Step(
function () { self.hasQemu(this) },
function (err, hasQemu) {
if (err) cb(err);
else if (!hasQemu) {
function (hasQemu) {
if (!hasQemu) {
cb('Qemu not detected in $PATH with `which qemu`. '
+ ' If you still want to install, specify --no-qemu');
}
else {
path.exists(dir, this.parallel());
path.exists(dir + '/users', this.parallel());
path.exists(dir + '/data', this.parallel());
}
},
function mkdirs (err, root, users, data) {
function (hasRoot) {
if (!hasRoot) fs.mkdir(dir, 0700, this)
else this(null);
},
function (err) {
if (err) cb(err);
else if (users[0]) {
cb(dir + '/users directory already exists');
}
else if (data[0]) {
cb(dir + '/data directory already exists');
}
else if (!root[0]) {
fs.mkdir(dir, 0700, (function (err) {
mkdirs.bind(this)(err, [true], [false], [false]);
}).bind(this));
path.exists(dir + '/users', this.parallel().bind(this, null));
path.exists(dir + '/data', this.parallel().bind(this, null));
},
function (err, users, data) {
if (err) cb(err);
else if (users || data) {
cb('Directories already exist in ' + dir + ': '
+ Hash(['users','data'],[users,data])
.filter(Boolean).keys.join(' ')
)
}
else {
fs.mkdir(dir + '/users', 0700, this.parallel());
Expand Down

0 comments on commit 31c3eba

Please sign in to comment.