Cosmetic (tabbing).

This commit is contained in:
Arthur Britto
2012-09-15 14:56:15 -07:00
parent 3a9c82c1cc
commit f45886cc6d
3 changed files with 69 additions and 66 deletions

View File

@@ -33,3 +33,4 @@ var start = function(name, done) {
exports.start = start; exports.start = start;
console.log("server.js<"); console.log("server.js<");
// vim:ts=4

View File

@@ -7,11 +7,12 @@ var server = require("./server.js");
buster.testCase("Check standalone server startup", { buster.testCase("Check standalone server startup", {
"Start": function (done) { "Start": function (done) {
server.start("alpha", function(e) { server.start("alpha", function(e) {
buster.refute(e); buster.refute(e);
done(); done();
}); });
} }
}); });
// console.log("standalone-test.js<"); // console.log("standalone-test.js<");
// vim:ts=4

View File

@@ -4,34 +4,34 @@ var path = require("path");
var filterErr = function(code, done) { var filterErr = function(code, done) {
return function (e) { return function (e) {
done(e.code !== code ? e : undefined); done(e.code !== code ? e : undefined);
} };
}; };
var throwErr = function(done) { var throwErr = function(done) {
return function (e) { return function (e) {
if (e) if (e)
throw e; throw e;
done(); done();
}; };
}; };
// apply function to elements of array. Return first true value to done or undefined. // apply function to elements of array. Return first true value to done or undefined.
var mapOr = function(func, array, done) { var mapOr = function(func, array, done) {
if (array.length) { if (array.length) {
func(array[array.length-1], function (v) { func(array[array.length-1], function (v) {
if (v) { if (v) {
done(v); done(v);
} }
else { else {
array.length -= 1; array.length -= 1;
mapOr(func, array, done); mapOr(func, array, done);
} }
}); });
} }
else { else {
done(); done();
} }
}; };
@@ -39,23 +39,23 @@ var mapOr = function(func, array, done) {
var mkPath = function(dirPath, mode, done) { var mkPath = function(dirPath, mode, done) {
fs.mkdir(dirPath, mode, function (e) { fs.mkdir(dirPath, mode, function (e) {
if (e && e.code === "EEXIST") { if (e && e.code === "EEXIST") {
// Already exists, done. // Already exists, done.
done(); done();
} }
else if (e.code === "ENOENT") { else if (e.code === "ENOENT") {
// Missing sub dir. // Missing sub dir.
mkPath(path.dirname(dirPath), mode, function(e) { mkPath(path.dirname(dirPath), mode, function(e) {
if (e) { if (e) {
throw e; throw e;
} }
else { else {
mkPath(dirPath, mode, done); mkPath(dirPath, mode, done);
} }
}); });
} }
else { else {
throw e; throw e;
} }
}); });
}; };
@@ -74,50 +74,50 @@ var emptyPath = function(dirPath, done) {
// Remove path recursively. // Remove path recursively.
var rmPath = function(dirPath, done) { var rmPath = function(dirPath, done) {
// console.log("rmPath: %s", dirPath); console.log("rmPath: %s", dirPath);
fs.lstat(dirPath, function (err, stats) { fs.lstat(dirPath, function (err, stats) {
if (err && err.code == "ENOENT") { if (err && err.code == "ENOENT") {
done(); done();
} }
if (err) { if (err) {
done(err); done(err);
} }
else if (stats.isDirectory()) { else if (stats.isDirectory()) {
emptyPath(dirPath, function (e) { emptyPath(dirPath, function (e) {
if (e) { if (e) {
done(e); done(e);
} }
else { else {
// console.log("rmdir: %s", dirPath); done(); // console.log("rmdir: %s", dirPath); done();
fs.rmdir(dirPath, done); fs.rmdir(dirPath, done);
} }
});
}
else {
// console.log("unlink: %s", dirPath); done();
fs.unlink(dirPath, done);
}
}); });
}
else {
// console.log("unlink: %s", dirPath); done();
fs.unlink(dirPath, done);
}
});
}; };
// Create directory if needed and empty if needed. // Create directory if needed and empty if needed.
var resetPath = function(dirPath, mode, done) { var resetPath = function(dirPath, mode, done) {
mkPath(dirPath, mode, function (e) { mkPath(dirPath, mode, function (e) {
if (e) { if (e) {
done(e); done(e);
} }
else { else {
emptyPath(dirPath, done); emptyPath(dirPath, done);
} }
}); });
}; };
var trace = function(comment, func) { var trace = function(comment, func) {
return function() { return function() {
console.log("%s: %s", trace, arguments.toString); console.log("%s: %s", trace, arguments.toString);
func(arguments); func(arguments);
}; };
}; };
exports.emptyPath = emptyPath; exports.emptyPath = emptyPath;
@@ -127,3 +127,4 @@ exports.resetPath = resetPath;
exports.rmPath = rmPath; exports.rmPath = rmPath;
exports.trace = trace; exports.trace = trace;
// vim:ts=4