This commit is contained in:
Henry Oswald 2015-02-12 09:21:48 +00:00
commit 65859468de
2 changed files with 24 additions and 1 deletions

View file

@ -3,7 +3,11 @@ logger = require "logger-sharelatex"
metrics = require "../../infrastructure/Metrics"
module.exports = ArchiveManager =
extractZipArchive: (source, destination, callback = (err) ->) ->
extractZipArchive: (source, destination, _callback = (err) ->) ->
callback = (args...) ->
_callback(args...)
_callback = () ->
timer = new metrics.Timer("unzipDirectory")
logger.log source: source, destination: destination, "unzipping file"
@ -18,6 +22,12 @@ module.exports = ArchiveManager =
error ||= ""
error += chunk
unzip.on "error", (err) ->
logger.error {err, source, destination}, "unzip failed"
if err.code == "ENOENT"
logger.error "unzip command not found. Please check the unzip command is installed"
callback(err)
unzip.on "exit", () ->
timer.done()
if error?

View file

@ -57,3 +57,16 @@ describe "ArchiveManager", ->
it "should log out the error", ->
@logger.error.called.should.equal true
describe "with an error on the process", ->
beforeEach (done) ->
@ArchiveManager.extractZipArchive @source, @destination, (error) =>
@callback(error)
done()
@process.emit "error", new Error("Something went wrong")
it "should return the callback with an error", ->
@callback.calledWithExactly(new Error("Something went wrong")).should.equal true
it "should log out the error", ->
@logger.error.called.should.equal true