mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
Merge pull request #16806 from overleaf/ii-compile-dir-readonly
[clsi] Use readOnly bind-mounts for synctex and wordcount containers GitOrigin-RevId: 8de094350604544dba4571aa849ad41a4a4d88d8
This commit is contained in:
@@ -511,17 +511,12 @@ async function _runSynctex(projectId, userId, command, imageName) {
|
|||||||
async function wordcount(projectId, userId, filename, image) {
|
async function wordcount(projectId, userId, filename, image) {
|
||||||
logger.debug({ projectId, userId, filename, image }, 'running wordcount')
|
logger.debug({ projectId, userId, filename, image }, 'running wordcount')
|
||||||
const filePath = `$COMPILE_DIR/${filename}`
|
const filePath = `$COMPILE_DIR/${filename}`
|
||||||
const command = [
|
const command = ['texcount', '-nocol', '-inc', filePath]
|
||||||
'texcount',
|
|
||||||
'-nocol',
|
|
||||||
'-inc',
|
|
||||||
filePath,
|
|
||||||
`-out=${filePath}.wc`,
|
|
||||||
]
|
|
||||||
const compileDir = getCompileDir(projectId, userId)
|
const compileDir = getCompileDir(projectId, userId)
|
||||||
const timeout = 60 * 1000
|
const timeout = 60 * 1000
|
||||||
const compileName = getCompileName(projectId, userId)
|
const compileName = getCompileName(projectId, userId)
|
||||||
const compileGroup = 'wordcount'
|
const compileGroup = 'wordcount'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fsPromises.mkdir(compileDir, { recursive: true })
|
await fsPromises.mkdir(compileDir, { recursive: true })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -531,22 +526,23 @@ async function wordcount(projectId, userId, filename, image) {
|
|||||||
filename,
|
filename,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
await CommandRunner.promises.run(
|
|
||||||
compileName,
|
|
||||||
command,
|
|
||||||
compileDir,
|
|
||||||
image,
|
|
||||||
timeout,
|
|
||||||
{},
|
|
||||||
compileGroup
|
|
||||||
)
|
|
||||||
|
|
||||||
let stdout
|
|
||||||
try {
|
try {
|
||||||
stdout = await fsPromises.readFile(
|
const { stdout } = await CommandRunner.promises.run(
|
||||||
compileDir + '/' + filename + '.wc',
|
compileName,
|
||||||
'utf-8'
|
command,
|
||||||
|
compileDir,
|
||||||
|
image,
|
||||||
|
timeout,
|
||||||
|
{},
|
||||||
|
compileGroup
|
||||||
)
|
)
|
||||||
|
const results = _parseWordcountFromOutput(stdout)
|
||||||
|
logger.debug(
|
||||||
|
{ projectId, userId, wordcount: results },
|
||||||
|
'word count results'
|
||||||
|
)
|
||||||
|
return results
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw OError.tag(err, 'error reading word count output', {
|
throw OError.tag(err, 'error reading word count output', {
|
||||||
command,
|
command,
|
||||||
@@ -555,10 +551,6 @@ async function wordcount(projectId, userId, filename, image) {
|
|||||||
userId,
|
userId,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const results = _parseWordcountFromOutput(stdout)
|
|
||||||
logger.debug({ projectId, userId, wordcount: results }, 'word count results')
|
|
||||||
return results
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _parseWordcountFromOutput(output) {
|
function _parseWordcountFromOutput(output) {
|
||||||
|
|||||||
@@ -72,6 +72,10 @@ const DockerRunner = {
|
|||||||
image = `${Settings.texliveImageNameOveride}/${img[2]}`
|
image = `${Settings.texliveImageNameOveride}/${img[2]}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (compileGroup === 'synctex' || compileGroup === 'wordcount') {
|
||||||
|
volumes[directory] += ':ro'
|
||||||
|
}
|
||||||
|
|
||||||
const options = DockerRunner._getContainerOptions(
|
const options = DockerRunner._getContainerOptions(
|
||||||
command,
|
command,
|
||||||
image,
|
image,
|
||||||
|
|||||||
@@ -85,7 +85,15 @@ describe('CompileManager', function () {
|
|||||||
}
|
}
|
||||||
this.CommandRunner = {
|
this.CommandRunner = {
|
||||||
promises: {
|
promises: {
|
||||||
run: sinon.stub().resolves({ stdout: this.commandOutput }),
|
run: sinon.stub().callsFake((_1, _2, _3, _4, _5, _6, compileGroup) => {
|
||||||
|
if (compileGroup === 'synctex') {
|
||||||
|
return Promise.resolve({ stdout: this.commandOutput })
|
||||||
|
} else {
|
||||||
|
return Promise.resolve({
|
||||||
|
stdout: 'Encoding: ascii\nWords in text: 2',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
this.DraftModeManager = {
|
this.DraftModeManager = {
|
||||||
@@ -544,11 +552,6 @@ describe('CompileManager', function () {
|
|||||||
|
|
||||||
describe('wordcount', function () {
|
describe('wordcount', function () {
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
this.stdout = 'Encoding: ascii\nWords in text: 2'
|
|
||||||
this.fsPromises.readFile
|
|
||||||
.withArgs(Path.join(this.compileDir, 'main.tex.wc'))
|
|
||||||
.resolves(this.stdout)
|
|
||||||
|
|
||||||
this.timeout = 60 * 1000
|
this.timeout = 60 * 1000
|
||||||
this.filename = 'main.tex'
|
this.filename = 'main.tex'
|
||||||
this.image = 'example.com/image'
|
this.image = 'example.com/image'
|
||||||
@@ -563,13 +566,7 @@ describe('CompileManager', function () {
|
|||||||
|
|
||||||
it('should run the texcount command', function () {
|
it('should run the texcount command', function () {
|
||||||
this.filePath = `$COMPILE_DIR/${this.filename}`
|
this.filePath = `$COMPILE_DIR/${this.filename}`
|
||||||
this.command = [
|
this.command = ['texcount', '-nocol', '-inc', this.filePath]
|
||||||
'texcount',
|
|
||||||
'-nocol',
|
|
||||||
'-inc',
|
|
||||||
this.filePath,
|
|
||||||
`-out=${this.filePath}.wc`,
|
|
||||||
]
|
|
||||||
|
|
||||||
expect(this.CommandRunner.promises.run).to.have.been.calledWith(
|
expect(this.CommandRunner.promises.run).to.have.been.calledWith(
|
||||||
`${this.projectId}-${this.userId}`,
|
`${this.projectId}-${this.userId}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user