Просмотр исходного кода

listen for close not exit when working with unzip command

sometimes the command will fail because stout has not finished yet
Henry Oswald 10 лет назад
Родитель
Сommit
840d3b75bb

+ 3 - 5
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)

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