Explorar el Código

check directory exists and bail out on error

Brian Gough hace 9 años
padre
commit
550979991f
Se han modificado 1 ficheros con 14 adiciones y 5 borrados
  1. 14 5
      services/clsi/app/coffee/CompileManager.coffee

+ 14 - 5
services/clsi/app/coffee/CompileManager.coffee

@@ -202,16 +202,25 @@ module.exports = CompileManager =
 			callback null, CompileManager._parseSynctexFromPdfOutput(stdout, base_dir)
 
 	_checkFileExists: (path, callback = (error) ->) ->
-		fs.stat path, (err, stats) ->
-			return callback(err) if err?
-			return callback(new Error("not a file")) if not stats.isFile()
-			callback()
+		synctexDir = Path.dirname(path)
+		synctexFile = Path.join(synctexDir, "output.synctex.gz")
+		fs.stat synctexDir, (error, stats) ->
+			if error?.code is 'ENOENT'
+				return callback(new Error("called synctex with no output directory"))
+			return callback(error) if error?
+			fs.stat synctexFile, (error, stats) ->
+				if error?.code is 'ENOENT'
+					return callback(new Error("called synctex with no output file"))
+				return callback(error) if error?
+				return callback(new Error("not a file")) if not stats?.isFile()
+				callback()
 
 	_runSynctex: (args, callback = (error, stdout) ->) ->
 		bin_path = Path.resolve(__dirname + "/../../bin/synctex")
 		seconds = 1000
 		outputFilePath = args[1]
-		CompileManager._checkFileExists outputFilePath, (err) ->
+		CompileManager._checkFileExists outputFilePath, (error) ->
+			return callback(error) if error?
 			if Settings.clsi?.synctexCommandWrapper?
 				[bin_path, args] = Settings.clsi?.synctexCommandWrapper bin_path, args
 			child_process.execFile bin_path, args, timeout: 10 * seconds, (error, stdout, stderr) ->