UNPKG

mecano

Version:

Common functions for system deployment.

70 lines (66 loc) 1.83 kB
// Generated by CoffeeScript 1.11.1 var fs, uid_gid; module.exports = function(options, callback) { var do_chown, do_stat, do_uid_gid; options.log({ message: "Entering chown", level: 'DEBUG', module: 'mecano/lib/chown' }); if (options.target == null) { return callback(Error("Missing target 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); } options.log({ message: "Stat " + options.target, level: 'DEBUG', module: 'mecano/lib/chown' }); return fs.stat(options.ssh, options.target, 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) { options.log({ message: "Matching ownerships on '" + options.target + "'", level: 'INFO', module: 'mecano/lib/chown' }); return callback(); } return fs.chown(options.ssh, options.target, options.uid, options.gid, function(err) { options.log({ message: "change uid from " + stat.uid + " to " + options.uid, level: 'WARN', module: 'mecano/lib/chown' }); options.log({ message: "change gid from " + stat.gid + " to " + options.gid, level: 'WARN', module: 'mecano/lib/chown' }); return callback(err, true); }); }; return do_uid_gid(); }; fs = require('ssh2-fs'); uid_gid = require('../misc/uid_gid');