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,6 +203,10 @@ 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]
fse.ensureDir compileDir, (error) ->
if error?
logger.err {error, project_id, user_id, file_name}, "error ensuring dir for sync from code"
return callback(error)
CompileManager._runSynctex project_id, user_id, command, (error, stdout) -> CompileManager._runSynctex project_id, user_id, command, (error, stdout) ->
return callback(error) if error? return callback(error) if error?
if stdout.toLowerCase().indexOf("warning") == -1 if stdout.toLowerCase().indexOf("warning") == -1
@ -218,6 +222,10 @@ 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]
fse.ensureDir compileDir, (error) ->
if error?
logger.err {error, project_id, user_id, file_name}, "error ensuring dir for sync to code"
return callback(error)
CompileManager._runSynctex project_id, user_id, command, (error, stdout) -> CompileManager._runSynctex project_id, user_id, command, (error, stdout) ->
return callback(error) if error? 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" logger.log project_id: project_id, user_id:user_id, page: page, h: h, v:v, stdout: stdout, "synctex pdf output"
@ -282,16 +290,19 @@ 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?
logger.err {error, project_id, user_id, file_name}, "error ensuring dir for sync from code"
return callback(error)
CommandRunner.run compileName, command, compileDir, image, timeout, {}, (error) ->
return callback(error) if error? return callback(error) if error?
fs.readFile directory + "/" + file_name + ".wc", "utf-8", (err, stdout) -> fs.readFile compileDir + "/" + file_name + ".wc", "utf-8", (err, stdout) ->
if err? if err?
#call it node_err so sentry doesn't use random path error as unique id so it can't be ignored #call it node_err so sentry doesn't use random path error as unique id so it can't be ignored
logger.err node_err:err, command:command, directory:directory, project_id:project_id, user_id:user_id, "error reading word count output" logger.err node_err:err, command:command, compileDir:compileDir, project_id:project_id, user_id:user_id, "error reading word count output"
return callback(err) return callback(err)
results = CompileManager._parseWordcountFromOutput(stdout) results = CompileManager._parseWordcountFromOutput(stdout)
logger.log project_id:project_id, user_id:user_id, wordcount: results, "word count results" logger.log project_id:project_id, user_id:user_id, wordcount: results, "word count results"