mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-02 21:59:00 +02:00
[clsi] add helper function for detecting extraneous files (#24376)
* [clsi] add helper function for detecting extraneous files * [clsi] output.pdfxref and output.synctex.gz are extraneous as well * [clsi] minor code cleanup Co-authored-by: Mathias Jakobsen <mathias.jakobsen@overleaf.com> --------- Co-authored-by: Mathias Jakobsen <mathias.jakobsen@overleaf.com> GitOrigin-RevId: 0d6c96c99b6be3adaee1558b1f958da885e6307a
This commit is contained in:
@@ -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 () {}
|
||||
|
||||
@@ -107,7 +107,6 @@ Hello world
|
||||
'output.fdb_latexmk',
|
||||
'output.fls',
|
||||
'output.log',
|
||||
'output.pdfxref',
|
||||
'output.stderr',
|
||||
'output.stdout',
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user