From 6198b84cec95a6dc490982790dcfeb1a23713fed Mon Sep 17 00:00:00 2001 From: Patrick Stadler Date: Tue, 5 Aug 2014 11:47:34 +0200 Subject: [PATCH] use a temporary file to pass transfer list to rsync (fixes #1, #11, #21) --- lib/transport/shell.js | 15 +++++++++++---- package.json | 9 +++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/transport/shell.js b/lib/transport/shell.js index 85f3529..6dc143c 100644 --- a/lib/transport/shell.js +++ b/lib/transport/shell.js @@ -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'); @@ -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(); @@ -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)); @@ -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; }; diff --git a/package.json b/package.json index 5dc64b0..d8ad96b 100644 --- a/package.json +++ b/package.json @@ -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 ", "keywords": [ "deploy", @@ -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"