UNPKG

mecano

Version:

Common functions for system deployment.

101 lines (96 loc) 2.82 kB
// Generated by CoffeeScript 1.11.1 var docker, path, ssh2fs; module.exports = function(options) { var _, k, ref, ref1, ref2, source_container, source_mkdir, source_path, target_container, target_mkdir, target_path, v; options.log({ message: "Entering Docker cp", level: 'DEBUG', module: 'mecano/lib/docker/cp' }); if (options.docker == null) { options.docker = {}; } ref = options.docker; for (k in ref) { v = ref[k]; if (options[k] == null) { options[k] = v; } } if (!options.source) { throw Error('Missing option "source"'); } if (!options.target) { throw Error('Missing option "target"'); } ref1 = /(.*:)?(.*)/.exec(options.source), _ = ref1[0], source_container = ref1[1], source_path = ref1[2]; ref2 = /(.*:)?(.*)/.exec(options.target), _ = ref2[0], target_container = ref2[1], target_path = ref2[2]; if (source_container && target_container) { throw Error('Incompatible source and target options'); } if (!source_container && !target_container) { throw Error('Incompatible source and target options'); } source_mkdir = false; target_mkdir = false; this.call(function(_, next) { if (source_container) { return next(); } if (/\/$/.test(source_path)) { source_path = source_path + "/" + (path.basename(target_path)); return next(); } return ssh2fs.stat(options.ssh, source_path, function(err, stat) { if (err && err.code !== 'ENOENT') { return next(err); } if ((err != null ? err.code : void 0) === 'ENOENT') { return target_mkdir = true && next(); } if (stat.isDirectory()) { source_path = source_path + "/" + (path.basename(target_path)); } return next(); }); }); this.mkdir({ target: source_path, "if": function() { return source_mkdir; } }); this.call(function(_, next) { if (target_container) { return next(); } if (/\/$/.test(target_path)) { target_path = target_path + "/" + (path.basename(target_path)); return next(); } return ssh2fs.stat(options.ssh, target_path, function(err, stat) { if (err && err.code !== 'ENOENT') { return next(err); } if ((err != null ? err.code : void 0) === 'ENOENT') { return target_mkdir = true && next(); } if (stat.isDirectory()) { target_path = target_path + "/" + (path.basename(target_path)); } return next(); }); }); this.mkdir({ target: target_path, "if": function() { return target_mkdir; } }); return this.execute({ cmd: docker.wrap(options, "cp " + options.source + " " + options.target) }, docker.callback); }; path = require('path'); ssh2fs = require('ssh2-fs'); docker = require('../misc/docker');