UNPKG

mecano

Version:

Common functions for system deployment.

61 lines (57 loc) 1.89 kB
// Generated by CoffeeScript 1.9.1 var fs, uid_gid; module.exports = function(options, callback) { var do_chown, do_stat, do_uid_gid; if (options.destination == null) { return callback(Error("Missing destination option")); } if (!((options.uid != null) || (options.gid != null))) { return callback(Error("Missing one of uid or gid option")); } do_uid_gid = function() { return uid_gid(options, function(err) { if (err) { return callback(err); } return do_stat(); }); }; do_stat = function() { if (options.stat) { return do_chown(options.stat); } if (typeof options.log === "function") { options.log("Mecano `chown`: stat " + options.destination + " [DEBUG]"); } return fs.stat(options.ssh, options.destination, function(err, stat) { if (err) { return callback(err); } return do_chown(stat); }); }; do_chown = function(stat) { if (stat.uid === options.uid && stat.gid === options.gid) { if (typeof options.log === "function") { options.log("Mecano `chmod`: identical ownerships on '" + options.destination + "' [INFO]"); } return callback(); } return fs.chown(options.ssh, options.destination, options.uid, options.gid, function(err) { if (options.uid && stat.uid !== options.uid) { if (typeof options.log === "function") { options.log("Mecano `chown`: change uid from " + stat.uid + " to " + options.uid + " [WARN]"); } } if (options.gid && stat.gid !== options.gid) { if (typeof options.log === "function") { options.log("Mecano `chown`: change gid from " + stat.gid + " to " + options.gid + " [WARN]"); } } return callback(err, true); }); }; return do_uid_gid(); }; fs = require('ssh2-fs'); uid_gid = require('./misc/uid_gid');