mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-16 17:41:21 +00:00
Merge pull request #19296 from overleaf/jpa-issue-19290-3
[clsi] atomic writing of LaTeXMk output GitOrigin-RevId: d81c497370587b98fc7ad282035cd59b0ae09ec8
This commit is contained in:
parent
51a24601ec
commit
9f68bc5660
2 changed files with 21 additions and 7 deletions
|
@ -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()
|
||||
|
|
|
@ -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'
|
||||
)
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue