From b5346658b066bfa5c99f108a0601f38764ca00ec Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Wed, 16 Dec 2020 15:14:18 +0000 Subject: [PATCH] clear output directory when clearing project --- services/clsi/app/js/CompileManager.js | 13 +++++++++++-- .../clsi/test/unit/js/CompileManagerTests.js | 18 +++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/services/clsi/app/js/CompileManager.js b/services/clsi/app/js/CompileManager.js index 5dab554ff2..25741005f8 100644 --- a/services/clsi/app/js/CompileManager.js +++ b/services/clsi/app/js/CompileManager.js @@ -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}`) + ) } }) }) diff --git a/services/clsi/test/unit/js/CompileManagerTests.js b/services/clsi/test/unit/js/CompileManagerTests.js index cb85f2f131..917dfe8cb7 100644 --- a/services/clsi/test/unit/js/CompileManagerTests.js +++ b/services/clsi/test/unit/js/CompileManagerTests.js @@ -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}` ) }) })