From 840d3b75bb4cd8f93dc2435362653be8c332a2e1 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Mon, 21 Mar 2016 16:37:29 +0000 Subject: [PATCH] listen for close not exit when working with unzip command sometimes the command will fail because stout has not finished yet --- .../coffee/Features/Uploads/ArchiveManager.coffee | 8 +++----- .../coffee/Uploads/ArchiveManagerTests.coffee | 14 +++++++------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/services/web/app/coffee/Features/Uploads/ArchiveManager.coffee b/services/web/app/coffee/Features/Uploads/ArchiveManager.coffee index 5185c5d49c..645828ca6d 100644 --- a/services/web/app/coffee/Features/Uploads/ArchiveManager.coffee +++ b/services/web/app/coffee/Features/Uploads/ArchiveManager.coffee @@ -30,7 +30,7 @@ module.exports = ArchiveManager = logger.error "unzip command not found. Please check the unzip command is installed" callback(err) - unzip.on "exit", () -> + unzip.on "close", (exitCode) -> if error? error = new Error(error) logger.error err:error, source: source, "error checking zip size" @@ -42,7 +42,7 @@ module.exports = ArchiveManager = totalSizeInBytesAsInt = parseInt(totalSizeInBytes) if !totalSizeInBytesAsInt? or isNaN(totalSizeInBytesAsInt) - logger.err source:source, totalSizeInBytes:totalSizeInBytes, totalSizeInBytesAsInt:totalSizeInBytesAsInt, lastLine:lastLine, "error getting bytes of zip" + logger.err source:source, totalSizeInBytes:totalSizeInBytes, totalSizeInBytesAsInt:totalSizeInBytesAsInt, lastLine:lastLine, exitCode:exitCode, "error getting bytes of zip" return callback(new Error("error getting bytes of zip")) isTooLarge = totalSizeInBytes > (ONE_MEG * 300) @@ -50,8 +50,6 @@ module.exports = ArchiveManager = callback(error, isTooLarge) - - extractZipArchive: (source, destination, _callback = (err) ->) -> callback = (args...) -> @@ -87,7 +85,7 @@ module.exports = ArchiveManager = logger.error "unzip command not found. Please check the unzip command is installed" callback(err) - unzip.on "exit", () -> + unzip.on "close", () -> timer.done() if error? error = new Error(error) diff --git a/services/web/test/UnitTests/coffee/Uploads/ArchiveManagerTests.coffee b/services/web/test/UnitTests/coffee/Uploads/ArchiveManagerTests.coffee index 89b14c78c9..eab3d2fcbd 100644 --- a/services/web/test/UnitTests/coffee/Uploads/ArchiveManagerTests.coffee +++ b/services/web/test/UnitTests/coffee/Uploads/ArchiveManagerTests.coffee @@ -39,7 +39,7 @@ describe "ArchiveManager", -> describe "successfully", -> beforeEach (done) -> @ArchiveManager.extractZipArchive @source, @destination, done - @process.emit "exit" + @process.emit "close" it "should run unzip", -> @child.spawn.calledWithExactly("unzip", [@source, "-d", @destination]).should.equal true @@ -56,7 +56,7 @@ describe "ArchiveManager", -> @callback(error) done() @process.stderr.emit "data", "Something went wrong" - @process.emit "exit" + @process.emit "close" it "should return the callback with an error", -> @callback.calledWithExactly(new Error("Something went wrong")).should.equal true @@ -99,35 +99,35 @@ describe "ArchiveManager", -> isTooLarge.should.equal false done() @process.stdout.emit "data", @output("109042") - @process.emit "exit" + @process.emit "close" it "should return true with large bytes", (done)-> @ArchiveManager._isZipTooLarge @source, (error, isTooLarge) => isTooLarge.should.equal true done() @process.stdout.emit "data", @output("1090000000000000042") - @process.emit "exit" + @process.emit "close" it "should return error on no data", (done)-> @ArchiveManager._isZipTooLarge @source, (error, isTooLarge) => expect(error).to.exist done() @process.stdout.emit "data", "" - @process.emit "exit" + @process.emit "close" it "should return error if it didn't get a number", (done)-> @ArchiveManager._isZipTooLarge @source, (error, isTooLarge) => expect(error).to.exist done() @process.stdout.emit "data", @output("total_size_string") - @process.emit "exit" + @process.emit "close" it "should return error if the is only a bit of data", (done)-> @ArchiveManager._isZipTooLarge @source, (error, isTooLarge) => expect(error).to.exist done() @process.stdout.emit "data", " Length Date Time Name \n--------" - @process.emit "exit" + @process.emit "close" describe "findTopLevelDirectory", -> beforeEach ->