mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
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:
parent
4d7ed1cb17
commit
840d3b75bb
2 changed files with 10 additions and 12 deletions
|
@ -30,7 +30,7 @@ module.exports = ArchiveManager =
|
||||||
logger.error "unzip command not found. Please check the unzip command is installed"
|
logger.error "unzip command not found. Please check the unzip command is installed"
|
||||||
callback(err)
|
callback(err)
|
||||||
|
|
||||||
unzip.on "exit", () ->
|
unzip.on "close", (exitCode) ->
|
||||||
if error?
|
if error?
|
||||||
error = new Error(error)
|
error = new Error(error)
|
||||||
logger.error err:error, source: source, "error checking zip size"
|
logger.error err:error, source: source, "error checking zip size"
|
||||||
|
@ -42,7 +42,7 @@ module.exports = ArchiveManager =
|
||||||
totalSizeInBytesAsInt = parseInt(totalSizeInBytes)
|
totalSizeInBytesAsInt = parseInt(totalSizeInBytes)
|
||||||
|
|
||||||
if !totalSizeInBytesAsInt? or isNaN(totalSizeInBytesAsInt)
|
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"))
|
return callback(new Error("error getting bytes of zip"))
|
||||||
|
|
||||||
isTooLarge = totalSizeInBytes > (ONE_MEG * 300)
|
isTooLarge = totalSizeInBytes > (ONE_MEG * 300)
|
||||||
|
@ -50,8 +50,6 @@ module.exports = ArchiveManager =
|
||||||
callback(error, isTooLarge)
|
callback(error, isTooLarge)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extractZipArchive: (source, destination, _callback = (err) ->) ->
|
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"
|
logger.error "unzip command not found. Please check the unzip command is installed"
|
||||||
callback(err)
|
callback(err)
|
||||||
|
|
||||||
unzip.on "exit", () ->
|
unzip.on "close", () ->
|
||||||
timer.done()
|
timer.done()
|
||||||
if error?
|
if error?
|
||||||
error = new Error(error)
|
error = new Error(error)
|
||||||
|
|
|
@ -39,7 +39,7 @@ describe "ArchiveManager", ->
|
||||||
describe "successfully", ->
|
describe "successfully", ->
|
||||||
beforeEach (done) ->
|
beforeEach (done) ->
|
||||||
@ArchiveManager.extractZipArchive @source, @destination, done
|
@ArchiveManager.extractZipArchive @source, @destination, done
|
||||||
@process.emit "exit"
|
@process.emit "close"
|
||||||
|
|
||||||
it "should run unzip", ->
|
it "should run unzip", ->
|
||||||
@child.spawn.calledWithExactly("unzip", [@source, "-d", @destination]).should.equal true
|
@child.spawn.calledWithExactly("unzip", [@source, "-d", @destination]).should.equal true
|
||||||
|
@ -56,7 +56,7 @@ describe "ArchiveManager", ->
|
||||||
@callback(error)
|
@callback(error)
|
||||||
done()
|
done()
|
||||||
@process.stderr.emit "data", "Something went wrong"
|
@process.stderr.emit "data", "Something went wrong"
|
||||||
@process.emit "exit"
|
@process.emit "close"
|
||||||
|
|
||||||
it "should return the callback with an error", ->
|
it "should return the callback with an error", ->
|
||||||
@callback.calledWithExactly(new Error("Something went wrong")).should.equal true
|
@callback.calledWithExactly(new Error("Something went wrong")).should.equal true
|
||||||
|
@ -99,35 +99,35 @@ describe "ArchiveManager", ->
|
||||||
isTooLarge.should.equal false
|
isTooLarge.should.equal false
|
||||||
done()
|
done()
|
||||||
@process.stdout.emit "data", @output("109042")
|
@process.stdout.emit "data", @output("109042")
|
||||||
@process.emit "exit"
|
@process.emit "close"
|
||||||
|
|
||||||
it "should return true with large bytes", (done)->
|
it "should return true with large bytes", (done)->
|
||||||
@ArchiveManager._isZipTooLarge @source, (error, isTooLarge) =>
|
@ArchiveManager._isZipTooLarge @source, (error, isTooLarge) =>
|
||||||
isTooLarge.should.equal true
|
isTooLarge.should.equal true
|
||||||
done()
|
done()
|
||||||
@process.stdout.emit "data", @output("1090000000000000042")
|
@process.stdout.emit "data", @output("1090000000000000042")
|
||||||
@process.emit "exit"
|
@process.emit "close"
|
||||||
|
|
||||||
it "should return error on no data", (done)->
|
it "should return error on no data", (done)->
|
||||||
@ArchiveManager._isZipTooLarge @source, (error, isTooLarge) =>
|
@ArchiveManager._isZipTooLarge @source, (error, isTooLarge) =>
|
||||||
expect(error).to.exist
|
expect(error).to.exist
|
||||||
done()
|
done()
|
||||||
@process.stdout.emit "data", ""
|
@process.stdout.emit "data", ""
|
||||||
@process.emit "exit"
|
@process.emit "close"
|
||||||
|
|
||||||
it "should return error if it didn't get a number", (done)->
|
it "should return error if it didn't get a number", (done)->
|
||||||
@ArchiveManager._isZipTooLarge @source, (error, isTooLarge) =>
|
@ArchiveManager._isZipTooLarge @source, (error, isTooLarge) =>
|
||||||
expect(error).to.exist
|
expect(error).to.exist
|
||||||
done()
|
done()
|
||||||
@process.stdout.emit "data", @output("total_size_string")
|
@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)->
|
it "should return error if the is only a bit of data", (done)->
|
||||||
@ArchiveManager._isZipTooLarge @source, (error, isTooLarge) =>
|
@ArchiveManager._isZipTooLarge @source, (error, isTooLarge) =>
|
||||||
expect(error).to.exist
|
expect(error).to.exist
|
||||||
done()
|
done()
|
||||||
@process.stdout.emit "data", " Length Date Time Name \n--------"
|
@process.stdout.emit "data", " Length Date Time Name \n--------"
|
||||||
@process.emit "exit"
|
@process.emit "close"
|
||||||
|
|
||||||
describe "findTopLevelDirectory", ->
|
describe "findTopLevelDirectory", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
|
Loading…
Reference in a new issue