listen for close not exit when working with unzip command

sometimes the command will fail because stout has not finished yet
This commit is contained in:
Henry Oswald 2016-03-21 16:37:29 +00:00
parent 4d7ed1cb17
commit 840d3b75bb
2 changed files with 10 additions and 12 deletions

View file

@ -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)
@ -51,8 +51,6 @@ module.exports = ArchiveManager =
extractZipArchive: (source, destination, _callback = (err) ->) ->
callback = (args...) ->
_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)

View file

@ -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 ->