check output file exists before running synctex

This commit is contained in:
Brian Gough
2020-06-12 15:15:27 +01:00
parent 19690e7847
commit 33d6462875

View File

@@ -430,15 +430,7 @@ module.exports = CompileManager = {
const compileDir = getCompileDir(project_id, user_id) const compileDir = getCompileDir(project_id, user_id)
const synctex_path = `${base_dir}/output.pdf` const synctex_path = `${base_dir}/output.pdf`
const command = ['code', synctex_path, file_path, line, column] const command = ['code', synctex_path, file_path, line, column]
return fse.ensureDir(compileDir, function(error) { CompileManager._runSynctex(project_id, user_id, command, function(
if (error != null) {
logger.err(
{ error, project_id, user_id, file_name },
'error ensuring dir for sync from code'
)
return callback(error)
}
return CompileManager._runSynctex(project_id, user_id, command, function(
error, error,
stdout stdout
) { ) {
@@ -449,11 +441,7 @@ module.exports = CompileManager = {
{ project_id, user_id, file_name, line, column, command, stdout }, { project_id, user_id, file_name, line, column, command, stdout },
'synctex code output' 'synctex code output'
) )
return callback( return callback(null, CompileManager._parseSynctexFromCodeOutput(stdout))
null,
CompileManager._parseSynctexFromCodeOutput(stdout)
)
})
}) })
}, },
@@ -466,15 +454,7 @@ module.exports = CompileManager = {
const base_dir = Settings.path.synctexBaseDir(compileName) const base_dir = Settings.path.synctexBaseDir(compileName)
const synctex_path = `${base_dir}/output.pdf` const synctex_path = `${base_dir}/output.pdf`
const command = ['pdf', synctex_path, page, h, v] const command = ['pdf', synctex_path, page, h, v]
return fse.ensureDir(compileDir, function(error) { CompileManager._runSynctex(project_id, user_id, command, function(
if (error != null) {
logger.err(
{ error, project_id, user_id, file_name },
'error ensuring dir for sync to code'
)
return callback(error)
}
return CompileManager._runSynctex(project_id, user_id, command, function(
error, error,
stdout stdout
) { ) {
@@ -490,29 +470,23 @@ module.exports = CompileManager = {
CompileManager._parseSynctexFromPdfOutput(stdout, base_dir) CompileManager._parseSynctexFromPdfOutput(stdout, base_dir)
) )
}) })
})
}, },
_checkFileExists(path, callback) { _checkFileExists(dir, filename, callback) {
if (callback == null) { if (callback == null) {
callback = function(error) {} callback = function(error) {}
} }
const synctexDir = Path.dirname(path) const file = Path.join(dir, filename)
const synctexFile = Path.join(synctexDir, 'output.synctex.gz') return fs.stat(dir, function(error, stats) {
return fs.stat(synctexDir, function(error, stats) {
if ((error != null ? error.code : undefined) === 'ENOENT') { if ((error != null ? error.code : undefined) === 'ENOENT') {
return callback( return callback(new Errors.NotFoundError('no output directory'))
new Errors.NotFoundError('called synctex with no output directory')
)
} }
if (error != null) { if (error != null) {
return callback(error) return callback(error)
} }
return fs.stat(synctexFile, function(error, stats) { return fs.stat(file, function(error, stats) {
if ((error != null ? error.code : undefined) === 'ENOENT') { if ((error != null ? error.code : undefined) === 'ENOENT') {
return callback( return callback(new Errors.NotFoundError('no output file'))
new Errors.NotFoundError('called synctex with no output file')
)
} }
if (error != null) { if (error != null) {
return callback(error) return callback(error)
@@ -536,6 +510,10 @@ module.exports = CompileManager = {
const directory = getCompileDir(project_id, user_id) const directory = getCompileDir(project_id, user_id)
const timeout = 60 * 1000 // increased to allow for large projects const timeout = 60 * 1000 // increased to allow for large projects
const compileName = getCompileName(project_id, user_id) const compileName = getCompileName(project_id, user_id)
CompileManager._checkFileExists(directory, 'output.synctex.gz', error => {
if (error) {
return callback(error)
}
return CommandRunner.run( return CommandRunner.run(
compileName, compileName,
command, command,
@@ -554,6 +532,7 @@ module.exports = CompileManager = {
return callback(null, output.stdout) return callback(null, output.stdout)
} }
) )
})
}, },
_parseSynctexFromCodeOutput(output) { _parseSynctexFromCodeOutput(output) {