diff --git a/README.md b/README.md index 7494ab5..a298e20 100755 --- a/README.md +++ b/README.md @@ -156,6 +156,14 @@ pool.run('hostname') Same as `connection.copy`, except that the copy is done in parallel on each server of the pool. +**Options:** + +``` +@param {object} [options.direction] Direction of copy +``` + +Also all exec options are supported. + **Arguments:** ``` diff --git a/lib/connection.js b/lib/connection.js index 62f2ce0..118b536 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -106,6 +106,7 @@ Connection.prototype.run = function (command, options, cb) { * @param {string} src Source * @param {string} dest Destination * @param {object} [options] Exec Options + * @param {object} [options.direction] Direction of copy * @param {function} [cb] Callback * @returns {Promise} */ @@ -119,7 +120,7 @@ Connection.prototype.copy = function (src, dest, options, cb) { options = _.defaults(options || {}, { maxBuffer: 1000 * 1024, - direction: 'localToRemote', + direction: 'localToRemote' }); var connection = this; @@ -127,10 +128,14 @@ Connection.prototype.copy = function (src, dest, options, cb) { return new Promise(function (resolve, reject) { // Complete src. - var completeSrc = options.direction == 'remoteToLocal' ? remote.format(connection.remote) + ':' + src : src; + var completeSrc = options.direction === 'remoteToLocal' ? + remote.format(connection.remote) + ':' + src : + src; // Complete dest. - var completeDest = options.direction == 'localToRemote' ? remote.format(connection.remote) + ':' + dest : dest; + var completeDest = options.direction === 'localToRemote' ? + remote.format(connection.remote) + ':' + dest : + dest; // Format excludes. var excludes = options.ignores ? formatExcludes(options.ignores) : []; @@ -151,7 +156,7 @@ Connection.prototype.copy = function (src, dest, options, cb) { var stderrWrapper = new LineWrapper({prefix: '@' + connection.remote.host + '-err '}); // Exec command. - var child = exec(args.join(' '), options, function (err, stdout, stderr) { + var child = exec(args.join(' '), _.omit(options, 'direction'), function (err, stdout, stderr) { if (err) return reject(err); resolve({ child: child, @@ -177,7 +182,7 @@ Connection.prototype.copy = function (src, dest, options, cb) { function formatExcludes(excludes) { return excludes.reduce(function (prev, current) { - return prev.concat(['--exclude', '"' + current + '"']); + return prev.concat(['--exclude', '"' + current + '"']); }, []); } diff --git a/test/connection-pool.js b/test/connection-pool.js index 4c42b00..7cfef99 100644 --- a/test/connection-pool.js +++ b/test/connection-pool.js @@ -80,12 +80,12 @@ describe('SSH Connection pool', function () { expect(childProcess.exec).to.be.calledWith( 'rsync -az -e "ssh " /src/dir deploy@myserver:/dest/dir', - {maxBuffer: 1000 * 1024, direction: 'localToRemote'} + {maxBuffer: 1000 * 1024} ); expect(childProcess.exec).to.be.calledWith( 'rsync -az -e "ssh " /src/dir deploy@myserver2:/dest/dir', - {maxBuffer: 1000 * 1024, direction: 'localToRemote'} + {maxBuffer: 1000 * 1024} ); done();