Merge pull request #19296 from overleaf/jpa-issue-19290-3

[clsi] atomic writing of LaTeXMk output

GitOrigin-RevId: d81c497370587b98fc7ad282035cd59b0ae09ec8
This commit is contained in:
Jakob Ackermann 2024-07-05 18:29:04 +02:00 committed by Copybot
parent 51a24601ec
commit 9f68bc5660
2 changed files with 21 additions and 7 deletions

View file

@ -110,11 +110,14 @@ function _writeLogOutput(projectId, directory, output, 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({ err, projectId, file }, 'error writing log file') // don't fail on error
}
cb()
fs.unlink(file, () => {
fs.writeFile(file, content, { flag: 'wx' }, err => {
if (err) {
// don't fail on error
logger.error({ err, projectId, file }, 'error writing log file')
}
cb()
})
})
} else {
cb()

View file

@ -23,6 +23,9 @@ describe('LatexRunner', function () {
}
this.fs = {
writeFile: sinon.stub().yields(),
unlink: sinon
.stub()
.yields(new Error('ENOENT: no such file or directory, unlink ...')),
}
this.LatexRunner = SandboxedModule.require(MODULE_PATH, {
requires: {
@ -99,11 +102,19 @@ describe('LatexRunner', function () {
it('should record the stdout and stderr', function () {
this.fs.writeFile.should.have.been.calledWith(
this.directory + '/' + 'output.stdout',
'this is stdout'
'this is stdout',
{ flag: 'wx' }
)
this.fs.writeFile.should.have.been.calledWith(
this.directory + '/' + 'output.stderr',
'this is stderr'
'this is stderr',
{ flag: 'wx' }
)
this.fs.unlink.should.have.been.calledWith(
this.directory + '/' + 'output.stdout'
)
this.fs.unlink.should.have.been.calledWith(
this.directory + '/' + 'output.stderr'
)
})