From e98574e4ecb134ec3fdbee5ddaae81f5b710dc4f Mon Sep 17 00:00:00 2001 From: Radek Pazdera Date: Thu, 14 Dec 2017 12:21:00 +0000 Subject: [PATCH] Move from exec to spawn to avoid stdout buffer overflow --- lib/deploy-methods/s3.js | 21 ++++++++++++++++----- package.json | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/deploy-methods/s3.js b/lib/deploy-methods/s3.js index f117f80..91f5826 100644 --- a/lib/deploy-methods/s3.js +++ b/lib/deploy-methods/s3.js @@ -92,7 +92,9 @@ function _doReleaseBySync(build, target, data) { rs.pipe(write); write.on('finish', () => { - let env = Object.assign({}, process.env); + let env = Object.assign({}, process.env), + proc, + errBuffer = ""; if (config.local.awsKey) { env.AWS_ACCESS_KEY_ID = config.local.awsKey; @@ -102,16 +104,25 @@ function _doReleaseBySync(build, target, data) { env.AWS_SECRET_ACCESS_KEY = config.local.awsSecret; } - childProcess.exec(`aws s3 sync ${path} s3://${target}`, {env}, (err, stdout, stderr) => { - if (err) { + proc = childProcess.spawn('aws', ['s3', 'sync', path, `s3://${target}`], { + env: env, + stdio: ['pipe', 'ignore', 'pipe'], + shell: true + }); + proc.stderr.on('data', function (data) { + errBuffer += data + "\n"; + }); + + proc.on('close', function (code) { + if (code !== 0) { cleanupCb(); - if (err.toString().indexOf('aws: command not found')) { + if (errBuffer.toString().indexOf('aws: command not found') >= 0) { console.log('It looks like you don\'t have the `aws` command on your system that is required to deploy this build.'); console.log('See https://aws.amazon.com/cli/ for instructions how to inststall the AWS CLI.'); } - return reject('Sync failed: ' + err); + return reject('Sync failed: ' + errBuffer.trim()); } cleanupCb(); diff --git a/package.json b/package.json index 56ffdfc..8a462a0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kart", - "version": "0.4.4", + "version": "0.4.5", "description": "Kano Archive and Release Tool. Managing releases mainly of static websites.", "main": "lib/index.js", "bin": {