fse.ensureDir when running synctex and wordcount

This commit is contained in:
Henry Oswald 2018-08-23 08:34:18 +01:00
parent 2aaadc6124
commit 59638c261d
2 changed files with 35 additions and 26 deletions

View file

@ -82,7 +82,6 @@ module.exports = CompileController =
column = parseInt(req.query.column, 10) column = parseInt(req.query.column, 10)
project_id = req.params.project_id project_id = req.params.project_id
user_id = req.params.user_id user_id = req.params.user_id
CompileManager.syncFromCode project_id, user_id, file, line, column, (error, pdfPositions) -> CompileManager.syncFromCode project_id, user_id, file, line, column, (error, pdfPositions) ->
return next(error) if error? return next(error) if error?
res.send JSON.stringify { res.send JSON.stringify {
@ -95,7 +94,6 @@ module.exports = CompileController =
v = parseFloat(req.query.v) v = parseFloat(req.query.v)
project_id = req.params.project_id project_id = req.params.project_id
user_id = req.params.user_id user_id = req.params.user_id
CompileManager.syncFromPdf project_id, user_id, page, h, v, (error, codePositions) -> CompileManager.syncFromPdf project_id, user_id, page, h, v, (error, codePositions) ->
return next(error) if error? return next(error) if error?
res.send JSON.stringify { res.send JSON.stringify {

View file

@ -203,14 +203,18 @@ module.exports = CompileManager =
compileDir = getCompileDir(project_id, user_id) compileDir = getCompileDir(project_id, user_id)
synctex_path = "#{base_dir}/output.pdf" synctex_path = "#{base_dir}/output.pdf"
command = ["code", synctex_path, file_path, line, column] command = ["code", synctex_path, file_path, line, column]
CompileManager._runSynctex project_id, user_id, command, (error, stdout) -> fse.ensureDir compileDir, (error) ->
return callback(error) if error? if error?
if stdout.toLowerCase().indexOf("warning") == -1 logger.err {error, project_id, user_id, file_name}, "error ensuring dir for sync from code"
logType = "log" return callback(error)
else CompileManager._runSynctex project_id, user_id, command, (error, stdout) ->
logType = "err" return callback(error) if error?
logger[logType] project_id: project_id, user_id:user_id, file_name: file_name, line: line, column: column, command:command, stdout: stdout, "synctex code output" if stdout.toLowerCase().indexOf("warning") == -1
callback null, CompileManager._parseSynctexFromCodeOutput(stdout) logType = "log"
else
logType = "err"
logger[logType] project_id: project_id, user_id:user_id, file_name: file_name, line: line, column: column, command:command, stdout: stdout, "synctex code output"
callback null, CompileManager._parseSynctexFromCodeOutput(stdout)
syncFromPdf: (project_id, user_id, page, h, v, callback = (error, filePositions) ->) -> syncFromPdf: (project_id, user_id, page, h, v, callback = (error, filePositions) ->) ->
compileName = getCompileName(project_id, user_id) compileName = getCompileName(project_id, user_id)
@ -218,10 +222,14 @@ module.exports = CompileManager =
base_dir = Settings.path.synctexBaseDir(compileName) base_dir = Settings.path.synctexBaseDir(compileName)
synctex_path = "#{base_dir}/output.pdf" synctex_path = "#{base_dir}/output.pdf"
command = ["pdf", synctex_path, page, h, v] command = ["pdf", synctex_path, page, h, v]
CompileManager._runSynctex project_id, user_id, command, (error, stdout) -> fse.ensureDir compileDir, (error) ->
return callback(error) if error? if error?
logger.log project_id: project_id, user_id:user_id, page: page, h: h, v:v, stdout: stdout, "synctex pdf output" logger.err {error, project_id, user_id, file_name}, "error ensuring dir for sync to code"
callback null, CompileManager._parseSynctexFromPdfOutput(stdout, base_dir) return callback(error)
CompileManager._runSynctex project_id, user_id, command, (error, stdout) ->
return callback(error) if error?
logger.log project_id: project_id, user_id:user_id, page: page, h: h, v:v, stdout: stdout, "synctex pdf output"
callback null, CompileManager._parseSynctexFromPdfOutput(stdout, base_dir)
_checkFileExists: (path, callback = (error) ->) -> _checkFileExists: (path, callback = (error) ->) ->
synctexDir = Path.dirname(path) synctexDir = Path.dirname(path)
@ -282,20 +290,23 @@ module.exports = CompileManager =
logger.log project_id:project_id, user_id:user_id, file_name:file_name, image:image, "running wordcount" logger.log project_id:project_id, user_id:user_id, file_name:file_name, image:image, "running wordcount"
file_path = "$COMPILE_DIR/" + file_name file_path = "$COMPILE_DIR/" + file_name
command = [ "texcount", '-nocol', '-inc', file_path, "-out=" + file_path + ".wc"] command = [ "texcount", '-nocol', '-inc', file_path, "-out=" + file_path + ".wc"]
directory = getCompileDir(project_id, user_id) compileDir = getCompileDir(project_id, user_id)
timeout = 10 * 1000 timeout = 10 * 1000
compileName = getCompileName(project_id, user_id) compileName = getCompileName(project_id, user_id)
fse.ensureDir compileDir, (error) ->
CommandRunner.run compileName, command, directory, image, timeout, {}, (error) -> if error?
return callback(error) if error? logger.err {error, project_id, user_id, file_name}, "error ensuring dir for sync from code"
fs.readFile directory + "/" + file_name + ".wc", "utf-8", (err, stdout) -> return callback(error)
if err? CommandRunner.run compileName, command, compileDir, image, timeout, {}, (error) ->
#call it node_err so sentry doesn't use random path error as unique id so it can't be ignored return callback(error) if error?
logger.err node_err:err, command:command, directory:directory, project_id:project_id, user_id:user_id, "error reading word count output" fs.readFile compileDir + "/" + file_name + ".wc", "utf-8", (err, stdout) ->
return callback(err) if err?
results = CompileManager._parseWordcountFromOutput(stdout) #call it node_err so sentry doesn't use random path error as unique id so it can't be ignored
logger.log project_id:project_id, user_id:user_id, wordcount: results, "word count results" logger.err node_err:err, command:command, compileDir:compileDir, project_id:project_id, user_id:user_id, "error reading word count output"
callback null, results return callback(err)
results = CompileManager._parseWordcountFromOutput(stdout)
logger.log project_id:project_id, user_id:user_id, wordcount: results, "word count results"
callback null, results
_parseWordcountFromOutput: (output) -> _parseWordcountFromOutput: (output) ->
results = { results = {