diff --git a/services/clsi/app/js/ResourceWriter.js b/services/clsi/app/js/ResourceWriter.js index 6fa6f85e1f..1db1c2baac 100644 --- a/services/clsi/app/js/ResourceWriter.js +++ b/services/clsi/app/js/ResourceWriter.js @@ -200,73 +200,22 @@ module.exports = ResourceWriter = { return OutputFileFinder.findOutputFiles( resources, basePath, - function (error, outputFiles, allFiles) { + (error, outputFiles, allFiles) => { if (error != null) { return callback(error) } const jobs = [] - for (const file of Array.from(outputFiles || [])) { - ;(function (file) { - const { path } = file - let shouldDelete = true - if ( - path.match(/^output\./) || - path.match(/\.aux$/) || - path.match(/^cache\//) - ) { - // knitr cache - shouldDelete = false - } - if (path.match(/^output-.*/)) { - // Tikz cached figures (default case) - shouldDelete = false - } - if (path.match(/\.(pdf|dpth|md5)$/)) { - // Tikz cached figures (by extension) - shouldDelete = false - } - if ( - path.match(/\.(pygtex|pygstyle)$/) || - path.match(/(^|\/)_minted-[^\/]+\//) - ) { - // minted files/directory - shouldDelete = false - } - if ( - path.match(/\.md\.tex$/) || - path.match(/(^|\/)_markdown_[^\/]+\//) - ) { - // markdown files/directory - shouldDelete = false - } - if (path.match(/-eps-converted-to\.pdf$/)) { - // Epstopdf generated files - shouldDelete = false - } - if ( - path === 'output.pdf' || - path === 'output.dvi' || - path === 'output.log' || - path === 'output.xdv' || - path === 'output.stdout' || - path === 'output.stderr' - ) { - shouldDelete = true - } - if (path === 'output.tex') { - // created by TikzManager if present in output files - shouldDelete = true - } - if (shouldDelete) { - return jobs.push(callback => - ResourceWriter._deleteFileIfNotDirectory( - Path.join(basePath, path), - callback - ) + for (const { path } of outputFiles || []) { + const shouldDelete = ResourceWriter.isExtraneousFile(path) + if (shouldDelete) { + jobs.push(callback => + ResourceWriter._deleteFileIfNotDirectory( + Path.join(basePath, path), + callback ) - } - })(file) + ) + } } return async.series(jobs, function (error) { @@ -279,6 +228,58 @@ module.exports = ResourceWriter = { ) }, + isExtraneousFile(path) { + let shouldDelete = true + if ( + path.match(/^output\./) || + path.match(/\.aux$/) || + path.match(/^cache\//) + ) { + // knitr cache + shouldDelete = false + } + if (path.match(/^output-.*/)) { + // Tikz cached figures (default case) + shouldDelete = false + } + if (path.match(/\.(pdf|dpth|md5)$/)) { + // Tikz cached figures (by extension) + shouldDelete = false + } + if ( + path.match(/\.(pygtex|pygstyle)$/) || + path.match(/(^|\/)_minted-[^\/]+\//) + ) { + // minted files/directory + shouldDelete = false + } + if (path.match(/\.md\.tex$/) || path.match(/(^|\/)_markdown_[^\/]+\//)) { + // markdown files/directory + shouldDelete = false + } + if (path.match(/-eps-converted-to\.pdf$/)) { + // Epstopdf generated files + shouldDelete = false + } + if ( + path === 'output.synctex.gz' || + path === 'output.pdfxref' || + path === 'output.pdf' || + path === 'output.dvi' || + path === 'output.log' || + path === 'output.xdv' || + path === 'output.stdout' || + path === 'output.stderr' + ) { + shouldDelete = true + } + if (path === 'output.tex') { + // created by TikzManager if present in output files + shouldDelete = true + } + return shouldDelete + }, + _deleteFileIfNotDirectory(path, callback) { if (callback == null) { callback = function () {} diff --git a/services/clsi/test/acceptance/js/BrokenLatexFileTests.js b/services/clsi/test/acceptance/js/BrokenLatexFileTests.js index 07c690738d..d22c142cff 100644 --- a/services/clsi/test/acceptance/js/BrokenLatexFileTests.js +++ b/services/clsi/test/acceptance/js/BrokenLatexFileTests.js @@ -107,7 +107,6 @@ Hello world 'output.fdb_latexmk', 'output.fls', 'output.log', - 'output.pdfxref', 'output.stderr', 'output.stdout', ])