mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Use system rm -r to allow removal of files with broken char encodings
This commit is contained in:
parent
841d1cb872
commit
b484f08d6e
3 changed files with 58 additions and 13 deletions
|
@ -5,7 +5,7 @@ Settings = require("settings-sharelatex")
|
|||
Path = require "path"
|
||||
logger = require "logger-sharelatex"
|
||||
Metrics = require "./Metrics"
|
||||
rimraf = require "rimraf"
|
||||
child_process = require "child_process"
|
||||
|
||||
module.exports = CompileManager =
|
||||
doCompile: (request, callback = (error, outputFiles) ->) ->
|
||||
|
@ -34,6 +34,21 @@ module.exports = CompileManager =
|
|||
return callback(error) if error?
|
||||
callback null, outputFiles
|
||||
|
||||
clearProject: (project_id, callback = (error) ->) ->
|
||||
clearProject: (project_id, _callback = (error) ->) ->
|
||||
callback = (error) ->
|
||||
_callback(error)
|
||||
_callback = () ->
|
||||
|
||||
compileDir = Path.join(Settings.path.compilesDir, project_id)
|
||||
rimraf compileDir, callback
|
||||
proc = child_process.spawn "rm", ["-r", compileDir]
|
||||
|
||||
proc.on "error", callback
|
||||
|
||||
stderr = ""
|
||||
proc.stderr.on "data", (chunk) -> stderr += chunk.toString()
|
||||
|
||||
proc.on "close", (code) ->
|
||||
if code == 0
|
||||
return callback(null)
|
||||
else
|
||||
return callback(new Error("rm -r #{compileDir} failed: #{stderr}"))
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
"mkdirp": "0.3.5",
|
||||
"mysql": "2.0.0-alpha7",
|
||||
"request": "~2.21.0",
|
||||
"rimraf": "2.1.4",
|
||||
"logger-sharelatex": "git+https://github.com/sharelatex/logger-sharelatex.git#master",
|
||||
"settings-sharelatex": "git+https://github.com/sharelatex/settings-sharelatex.git#master",
|
||||
"sequelize": "~2.0.0-beta.2",
|
||||
|
|
|
@ -3,6 +3,7 @@ sinon = require('sinon')
|
|||
require('chai').should()
|
||||
modulePath = require('path').join __dirname, '../../../app/js/CompileManager'
|
||||
tk = require("timekeeper")
|
||||
EventEmitter = require("events").EventEmitter
|
||||
|
||||
describe "CompileManager", ->
|
||||
beforeEach ->
|
||||
|
@ -12,7 +13,7 @@ describe "CompileManager", ->
|
|||
"./OutputFileFinder": @OutputFileFinder = {}
|
||||
"settings-sharelatex": @Settings = { path: compilesDir: "/compiles/dir" }
|
||||
"logger-sharelatex": @logger = { log: sinon.stub() }
|
||||
"rimraf": @rimraf = sinon.stub().callsArg(1)
|
||||
"child_process": @child_process = {}
|
||||
@callback = sinon.stub()
|
||||
|
||||
describe "doCompile", ->
|
||||
|
@ -61,13 +62,43 @@ describe "CompileManager", ->
|
|||
@callback.calledWith(null, @output_files).should.equal true
|
||||
|
||||
describe "clearProject", ->
|
||||
beforeEach ->
|
||||
@Settings.compileDir = "compiles"
|
||||
@CompileManager.clearProject @project_id, @callback
|
||||
describe "succesfully", ->
|
||||
beforeEach ->
|
||||
@Settings.compileDir = "compiles"
|
||||
@proc = new EventEmitter()
|
||||
@proc.stdout = new EventEmitter()
|
||||
@proc.stderr = new EventEmitter()
|
||||
@child_process.spawn = sinon.stub().returns(@proc)
|
||||
@CompileManager.clearProject @project_id, @callback
|
||||
@proc.emit "close", 0
|
||||
|
||||
it "should remove the project directory", ->
|
||||
@rimraf.calledWith("#{@Settings.path.compilesDir}/#{@project_id}")
|
||||
.should.equal true
|
||||
it "should remove the project directory", ->
|
||||
@child_process.spawn
|
||||
.calledWith("rm", ["-r", "#{@Settings.path.compilesDir}/#{@project_id}"])
|
||||
.should.equal true
|
||||
|
||||
it "should call the callback", ->
|
||||
@callback.called.should.equal true
|
||||
it "should call the callback", ->
|
||||
@callback.called.should.equal true
|
||||
|
||||
describe "with a non-success status code", ->
|
||||
beforeEach ->
|
||||
@Settings.compileDir = "compiles"
|
||||
@proc = new EventEmitter()
|
||||
@proc.stdout = new EventEmitter()
|
||||
@proc.stderr = new EventEmitter()
|
||||
@child_process.spawn = sinon.stub().returns(@proc)
|
||||
@CompileManager.clearProject @project_id, @callback
|
||||
@proc.stderr.emit "data", @error = "oops"
|
||||
@proc.emit "close", 1
|
||||
|
||||
it "should remove the project directory", ->
|
||||
@child_process.spawn
|
||||
.calledWith("rm", ["-r", "#{@Settings.path.compilesDir}/#{@project_id}"])
|
||||
.should.equal true
|
||||
|
||||
it "should call the callback with an error from the stderr", ->
|
||||
@callback
|
||||
.calledWith(new Error())
|
||||
.should.equal true
|
||||
|
||||
@callback.args[0][0].message.should.equal "rm -r #{@Settings.path.compilesDir}/#{@project_id} failed: #{@error}"
|
||||
|
|
Loading…
Reference in a new issue