UNPKG

mecano

Version:

Common functions for system deployment.

72 lines (65 loc) 2.05 kB
// 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 gid, ssh, uid; ssh = options.ssh, uid = options.uid, gid = options.gid; if (!options.destination) { return next(new Error("Missing destination: " + options.destination)); } if (!((uid != null) && (gid != null))) { return next(); } 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 (stat.uid === uid && stat.gid === gid) { return next(); } if (stat.uid !== uid) { if (typeof options.log === "function") { options.log("Change uid from " + stat.uid + " to " + uid); } } if (stat.gid !== gid) { if (typeof options.log === "function") { options.log("Change gid from " + stat.gid + " to " + gid); } } return fs.chown(ssh, options.destination, uid, gid, function(err) { if (err) { return next()(err); } modified++; return next(); }); }); }).on('both', function(err) { return finish(err, modified); }); }); };