From 7dbe2f02ee50dbbec86c5a4bfd5900532d39d9d3 Mon Sep 17 00:00:00 2001 From: abetomo Date: Tue, 2 May 2017 11:01:46 +0900 Subject: [PATCH 1/4] Fix to replace `_rsync` with `_filecopy` If there is a problem with `_ fileCopy`, it is possible to switch to `_rsync` in the environment variable --- lib/main.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/main.js b/lib/main.js index f012a6ca..0e473fd8 100644 --- a/lib/main.js +++ b/lib/main.js @@ -452,7 +452,16 @@ Lambda.prototype._archive = function (program, archive_callback) { Lambda.prototype._archivePrebuilt = function (program, archive_callback) { var codeDirectory = this._codeDirectory(program); var _this = this; - this._rsync(program, program.prebuiltDirectory, codeDirectory, false, function (err) { + + // It is switched to `_ rsync` by environment variable. + // (Used if there is a problem with `_ fileCopy`) + // If there is no problem even if deleting `_rsync`, this switching process is deleted + var copyFunction = '_fileCopy'; + if (process.env.NODE_LAMBDA_COPY_FUNCTION == 'rsync') { + console.log('=> INFO: Use rsync for copy'); + copyFunction = '_rsync'; + } + this[copyFunction](program, program.prebuiltDirectory, codeDirectory, false, function (err) { if (err) { return archive_callback(err); } @@ -484,8 +493,17 @@ Lambda.prototype._buildAndArchive = function (program, archive_callback) { return archive_callback(err); } console.log('=> Moving files to temporary directory'); + + // It is switched to `_ rsync` by environment variable. + // (Used if there is a problem with `_ fileCopy`) + // If there is no problem even if deleting `_rsync`, this switching process is deleted + var copyFunction = '_fileCopy'; + if (process.env.NODE_LAMBDA_COPY_FUNCTION == 'rsync') { + console.log('=> INFO: Use rsync for copy'); + copyFunction = '_rsync'; + } // Move files to tmp folder - _this._rsync(program, '.', codeDirectory, true, function (err) { + _this[copyFunction](program, '.', codeDirectory, true, function (err) { if (err) { return archive_callback(err); } From 3804eb67a802c9af18ea54c925f888f5f7040e52 Mon Sep 17 00:00:00 2001 From: abetomo Date: Tue, 2 May 2017 11:04:41 +0900 Subject: [PATCH 2/4] Fix to use `_fileCopy` in the tests --- test/main.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/main.js b/test/main.js index ff9b2014..25fbe059 100644 --- a/test/main.js +++ b/test/main.js @@ -162,7 +162,7 @@ describe('node-lambda', function () { }); it('`codeDirectory` is empty. (For `codeDirectory` where the file was present)', function (done) { - lambda._rsync(program, '.', codeDirectory, true, function (err, result) { + lambda._fileCopy(program, '.', codeDirectory, true, function (err, result) { const contents = fs.readdirSync(codeDirectory); assert.isTrue(contents.length > 0); lambda._cleanDirectory(codeDirectory, function () { @@ -295,7 +295,7 @@ describe('node-lambda', function () { return done(err); } - lambda._rsync(program, '.', codeDirectory, true, function (err) { + lambda._fileCopy(program, '.', codeDirectory, true, function (err) { if (err) { return done(err); } @@ -381,7 +381,7 @@ describe('node-lambda', function () { return done(err); } - lambda._rsync(program, '.', codeDirectory, true, function (err) { + lambda._fileCopy(program, '.', codeDirectory, true, function (err) { if (err) { return done(err); } From c7449cd65699494d7ec50c7151d98f5fb552da46 Mon Sep 17 00:00:00 2001 From: abetomo Date: Tue, 2 May 2017 11:05:30 +0900 Subject: [PATCH 3/4] Add a comment, `_rsync` is to delete --- lib/main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/main.js b/lib/main.js index 0e473fd8..aa97cb8d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -249,6 +249,7 @@ Lambda.prototype._fileCopy = function (program, src, dest, excludeNodeModules, c }); }; +// `_rsync` will be replaced by` _fileCopy`. Lambda.prototype._rsync = function (program, src, dest, excludeNodeModules, callback) { var excludes = ['.git*', '*.swp', '.editorconfig', '.lambda', 'deploy.env', '*.log', '/build/'], excludeGlobs = []; From 7d1ae2b3ea762a2272bbbbd0419bb55a20941f66 Mon Sep 17 00:00:00 2001 From: abetomo Date: Tue, 2 May 2017 11:07:17 +0900 Subject: [PATCH 4/4] Fix not to test `_rsync` on Windows --- test/main.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/main.js b/test/main.js index 25fbe059..424a4979 100644 --- a/test/main.js +++ b/test/main.js @@ -285,8 +285,12 @@ describe('node-lambda', function () { }); } - describe('_rsync', function() { rsyncTests('_rsync'); }); describe('_fileCopy', function() { rsyncTests('_fileCopy'); }); + if (process.platform == 'win32') { + it('For Windows, `_rsync` tests pending'); + } else { + describe('_rsync', function() { rsyncTests('_rsync'); }); + } describe('_npmInstall', function () { beforeEach(function (done) {