Преглед изворни кода

Merge branch 'master' of https://github.com/sharelatex/web-sharelatex

Henry Oswald пре 11 година
родитељ
комит
65859468de

+ 11 - 1
services/web/app/coffee/Features/Uploads/ArchiveManager.coffee

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

+ 13 - 0
services/web/test/UnitTests/coffee/Uploads/ArchiveManagerTests.coffee

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