mecano
Version:
Common functions for system deployment.
62 lines (55 loc) • 1.69 kB
JavaScript
// Generated by CoffeeScript 1.7.1
var child, conditions, each, fs, misc;
fs = require('ssh2-fs');
each = require('each');
misc = require('./misc');
conditions = require('./misc/conditions');
child = require('./misc/child');
module.exports = function(goptions, options, callback) {
var finish, result, _ref;
_ref = misc.args(arguments), goptions = _ref[0], options = _ref[1], callback = _ref[2];
result = child();
finish = function(err, modified) {
if (callback) {
callback(err, modified);
}
return result.end(err, modified);
};
return misc.options(options, function(err, options) {
var modified;
if (err) {
return finish(err);
}
modified = 0;
return each(options).parallel(goptions.parallel).on('item', function(options, next) {
var mode, ssh;
ssh = options.ssh, mode = options.mode;
if (!options.destination) {
return next(new Error("Missing destination: " + destination));
}
if (typeof options.log === "function") {
options.log("Stat " + options.destination);
}
return fs.stat(ssh, options.destination, function(err, stat) {
if (err) {
return next(err);
}
if (misc.file.cmpmod(stat.mode, mode)) {
return next();
}
if (typeof options.log === "function") {
options.log("Change mode to " + mode);
}
return fs.chmod(ssh, options.destination, mode, function(err) {
if (err) {
return next(err);
}
modified++;
return next();
});
});
}).on('both', function(err) {
return finish(err, modified);
});
});
};