Merge pull request #16440 from overleaf/jpa-em-remove-extra-stat

[clsi] remove unnecessary stat call for checking each output file

GitOrigin-RevId: ba7fe435264596368808552a3da3e36d731eda09
This commit is contained in:
Jakob Ackermann 2024-01-11 08:13:02 +00:00 committed by Copybot
parent 94594701e3
commit a0f8a1b806

View file

@ -266,13 +266,6 @@ module.exports = OutputCacheManager = {
const newFile = _.clone(file)
const src = Path.join(compileDir, file.path)
const dst = Path.join(cacheDir, file.path)
OutputCacheManager._checkFileIsSafe(src, function (err, isSafe) {
if (err) {
return cb(err)
}
if (!isSafe) {
return cb()
}
OutputCacheManager._checkIfShouldCopy(
src,
function (err, shouldCopy) {
@ -292,7 +285,6 @@ module.exports = OutputCacheManager = {
})
}
)
})
},
function (err) {
if (err) {
@ -497,13 +489,6 @@ module.exports = OutputCacheManager = {
function (file, cb) {
const src = Path.join(compileDir, file.path)
const dst = Path.join(archiveDir, file.path)
OutputCacheManager._checkFileIsSafe(src, function (err, isSafe) {
if (err) {
return cb(err)
}
if (!isSafe) {
return cb()
}
OutputCacheManager._checkIfShouldArchive(
src,
function (err, shouldArchive) {
@ -516,7 +501,6 @@ module.exports = OutputCacheManager = {
OutputCacheManager._copyFile(src, dst, dirCache, cb)
}
)
})
},
callback
)
@ -617,33 +601,6 @@ module.exports = OutputCacheManager = {
return path?.match(/^\.|\/\./) != null
},
_checkFileIsSafe(src, callback) {
// check if we have a valid file to copy into the cache
fs.stat(src, function (err, stats) {
if (err?.code === 'ENOENT') {
logger.warn(
{ err, file: src },
'file has disappeared before copying to build cache'
)
return callback(err, false)
} else if (err) {
// some other problem reading the file
logger.error({ err, file: src }, 'stat error for file in cache')
return callback(err, false)
} else if (!stats.isFile()) {
// other filetype - reject it
logger.warn(
{ src, stat: stats },
'nonfile output - refusing to copy to cache'
)
return callback(null, false)
} else {
// it's a plain file, ok to copy
return callback(null, true)
}
})
},
_ensureParentExists(dst, dirCache, callback) {
let parent = Path.dirname(dst)
if (dirCache.has(parent)) {