Skip to content
This repository has been archived by the owner on Mar 18, 2018. It is now read-only.

Commit

Permalink
Add documentation for direction options.
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Jan 27, 2015
1 parent ce4e1b9 commit 734d373
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**

```
Expand Down
15 changes: 10 additions & 5 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand All @@ -119,18 +120,22 @@ Connection.prototype.copy = function (src, dest, options, cb) {

options = _.defaults(options || {}, {
maxBuffer: 1000 * 1024,
direction: 'localToRemote',
direction: 'localToRemote'
});

var connection = this;

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) : [];
Expand All @@ -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,
Expand All @@ -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 + '"']);
}, []);
}

Expand Down
4 changes: 2 additions & 2 deletions test/connection-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 734d373

Please sign in to comment.