Skip to content

Commit

Permalink
use a temporary file to pass transfer list to rsync (fixes #1, #11, #21)
Browse files Browse the repository at this point in the history
  • Loading branch information
pstadler committed Aug 5, 2014
1 parent 6c7b581 commit 6198b84
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
15 changes: 11 additions & 4 deletions lib/transport/shell.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var util = require('util')
, fs = require('fs')
, exec = require("child_process").exec
, tempWrite = require('temp-write')
, Fiber = require('fibers')
, Future = require('fibers/future')
, Transport = require('./index');
Expand Down Expand Up @@ -68,12 +70,14 @@ ShellTransport.prototype.__transfer = function(files, remoteDir, options) {
files = files.stdout;
}

files = (files || '').trim().replace(/[\r|\n|\0]/mg, '\\n');
files = (files || '').trim().replace(/[\r|\0]/mg, '\n');
if(!files) {
throw new Error('transfer: empty file list passed');
}

var rsyncFlags = '-az' + (this.logger.debugEnabled() ? 'v': '');
var tmpTransferListFile = tempWrite.sync(files);

var rsyncFlags = '-az' + (this.logger.debugEnabled() ? 'vv': '');
var _results = [];
var task = function(config) {
var future = new Future();
Expand All @@ -84,8 +88,8 @@ ShellTransport.prototype.__transfer = function(files, remoteDir, options) {
, (config.username ? config.username + '@' : '')
, config.host, remoteDir);

var cmd = util.format('(printf "%s") | rsync --files-from - %s --rsh="ssh -p%s%s" ./ %s'
, files, rsyncFlags, config.port || 22
var cmd = util.format('rsync --files-from %s %s --rsh="ssh -p%s%s" ./ %s'
, tmpTransferListFile, rsyncFlags, config.port || 22
, sshFlags, remoteUrl);

_results.push(this.exec(cmd, options));
Expand All @@ -100,6 +104,9 @@ ShellTransport.prototype.__transfer = function(files, remoteDir, options) {
tasks.push(task(this.flight.hosts[i]));
}
Future.wait(tasks);

fs.unlink(tmpTransferListFile);

return _results;
};

Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "flightplan",
"description": "Library for streamlining application deployment or systems administration tasks",
"version": "0.4.1",
"version": "0.4.2",
"author": "Patrick Stadler <[email protected]>",
"keywords": [
"deploy",
Expand Down Expand Up @@ -34,12 +34,13 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"fibers": "~1.0.1",
"ssh2": "~0.2.17",
"colors": "~0.6.2",
"commander": "~2.1.0",
"fibers": "~1.0.1",
"pretty-hrtime": "~0.2.1",
"prompt": "~0.2.12",
"pretty-hrtime": "~0.2.1"
"ssh2": "~0.2.17",
"temp-write": "~0.3.1"
},
"optionalDependencies": {
"coffee-script": "~1.7.1"
Expand Down

0 comments on commit 6198b84

Please sign in to comment.