diff --git a/services/clsi/app/js/CompileManager.js b/services/clsi/app/js/CompileManager.js index 500adfcea0..3bf54bc75b 100644 --- a/services/clsi/app/js/CompileManager.js +++ b/services/clsi/app/js/CompileManager.js @@ -217,11 +217,6 @@ module.exports = CompileManager = { error = new Error('compilation') error.validate = 'fail' } - // make top-level output accesible to user, write in background for simplicity - if (output != null) { - fs.writeFile(Path.join(compileDir, "output.stdout"), output.stdout, () => { }) - fs.writeFile(Path.join(compileDir, "output.stderr"), output.stderr, () => { }) - } // compile was killed by user, was a validation, or a compile which failed validation if ( (error != null ? error.terminated : undefined) || diff --git a/services/clsi/app/js/LatexRunner.js b/services/clsi/app/js/LatexRunner.js index 972f1fe7c3..fe737c76c6 100644 --- a/services/clsi/app/js/LatexRunner.js +++ b/services/clsi/app/js/LatexRunner.js @@ -19,6 +19,7 @@ const Settings = require('settings-sharelatex') const logger = require('logger-sharelatex') const Metrics = require('./Metrics') const CommandRunner = require('./CommandRunner') +const fs = require('fs') const ProcessTable = {} // table of currently running jobs (pids or docker container names) @@ -127,9 +128,36 @@ module.exports = LatexRunner = { : undefined, x5 => x5[1] ) || 0 - return callback(error, output, stats, timings) + // record output files + LatexRunner.writeLogOutput(project_id, directory, output, () => { + return callback(error, output, stats, timings) + }) + })) + }, + + writeLogOutput(project_id, directory, output, callback) { + if (!output) { + return callback() + } + // internal method for writing non-empty log files + function _writeFile(file, content, cb) { + if (content && content.length > 0) { + fs.writeFile(file, content, (err) => { + if (err) { + logger.error({ project_id, file }, "error writing log file") // don't fail on error + } + cb() + }) + } else { + cb() } - )) + } + // write stdout and stderr, ignoring errors + _writeFile(Path.join(directory, "output.stdout"), output.stdout, () => { + _writeFile(Path.join(directory, "output.stderr"), output.stderr, () => { + callback() + }) + }) }, killLatex(project_id, callback) {