mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 21:23:45 +01:00
clear output directory when clearing project
This commit is contained in:
@@ -329,6 +329,7 @@ module.exports = CompileManager = {
|
||||
}
|
||||
|
||||
const compileDir = getCompileDir(project_id, user_id)
|
||||
const outputDir = getOutputDir(project_id, user_id)
|
||||
|
||||
return CompileManager._checkDirectory(compileDir, function (err, exists) {
|
||||
if (err != null) {
|
||||
@@ -338,7 +339,13 @@ module.exports = CompileManager = {
|
||||
return callback()
|
||||
} // skip removal if no directory present
|
||||
|
||||
const proc = child_process.spawn('rm', ['-r', compileDir])
|
||||
const proc = child_process.spawn('rm', [
|
||||
'-r',
|
||||
'-f',
|
||||
'--',
|
||||
compileDir,
|
||||
outputDir
|
||||
])
|
||||
|
||||
proc.on('error', callback)
|
||||
|
||||
@@ -349,7 +356,9 @@ module.exports = CompileManager = {
|
||||
if (code === 0) {
|
||||
return callback(null)
|
||||
} else {
|
||||
return callback(new Error(`rm -r ${compileDir} failed: ${stderr}`))
|
||||
return callback(
|
||||
new Error(`rm -r ${compileDir} ${outputDir} failed: ${stderr}`)
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -34,7 +34,8 @@ describe('CompileManager', function () {
|
||||
'./OutputCacheManager': (this.OutputCacheManager = {}),
|
||||
'settings-sharelatex': (this.Settings = {
|
||||
path: {
|
||||
compilesDir: '/compiles/dir'
|
||||
compilesDir: '/compiles/dir',
|
||||
outputDir: '/output/dir'
|
||||
},
|
||||
synctexBaseDir() {
|
||||
return '/compile'
|
||||
@@ -166,6 +167,7 @@ describe('CompileManager', function () {
|
||||
this.env = {}
|
||||
this.Settings.compileDir = 'compiles'
|
||||
this.compileDir = `${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}`
|
||||
this.outputDir = `${this.Settings.path.outputDir}/${this.project_id}-${this.user_id}`
|
||||
this.ResourceWriter.syncResourcesToDisk = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, this.resources)
|
||||
@@ -175,7 +177,7 @@ describe('CompileManager', function () {
|
||||
.callsArgWith(2, null, this.output_files)
|
||||
this.OutputCacheManager.saveOutputFiles = sinon
|
||||
.stub()
|
||||
.callsArgWith(2, null, this.build_files)
|
||||
.callsArgWith(3, null, this.build_files)
|
||||
this.DraftModeManager.injectDraftMode = sinon.stub().callsArg(1)
|
||||
return (this.TikzManager.checkMainFile = sinon.stub().callsArg(3, false))
|
||||
})
|
||||
@@ -312,7 +314,10 @@ describe('CompileManager', function () {
|
||||
return this.child_process.spawn
|
||||
.calledWith('rm', [
|
||||
'-r',
|
||||
`${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}`
|
||||
'-f',
|
||||
'--',
|
||||
`${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}`,
|
||||
`${this.Settings.path.outputDir}/${this.project_id}-${this.user_id}`
|
||||
])
|
||||
.should.equal(true)
|
||||
})
|
||||
@@ -348,7 +353,10 @@ describe('CompileManager', function () {
|
||||
return this.child_process.spawn
|
||||
.calledWith('rm', [
|
||||
'-r',
|
||||
`${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}`
|
||||
'-f',
|
||||
'--',
|
||||
`${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id}`,
|
||||
`${this.Settings.path.outputDir}/${this.project_id}-${this.user_id}`
|
||||
])
|
||||
.should.equal(true)
|
||||
})
|
||||
@@ -357,7 +365,7 @@ describe('CompileManager', function () {
|
||||
this.callback.calledWithExactly(sinon.match(Error)).should.equal(true)
|
||||
|
||||
this.callback.args[0][0].message.should.equal(
|
||||
`rm -r ${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id} failed: ${this.error}`
|
||||
`rm -r ${this.Settings.path.compilesDir}/${this.project_id}-${this.user_id} ${this.Settings.path.outputDir}/${this.project_id}-${this.user_id} failed: ${this.error}`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user