always create project directory when syncing resources to disk

avoids errors when project is empty
This commit is contained in:
Brian Gough 2016-03-31 11:25:25 +01:00
parent 308ca01b3c
commit 26e94f2549
2 changed files with 19 additions and 6 deletions

View file

@ -9,12 +9,25 @@ logger = require "logger-sharelatex"
module.exports = ResourceWriter =
syncResourcesToDisk: (project_id, resources, basePath, callback = (error) ->) ->
@_removeExtraneousFiles resources, basePath, (error) =>
@_createDirectory basePath, (error) =>
return callback(error) if error?
jobs = for resource in resources
do (resource) =>
(callback) => @_writeResourceToDisk(project_id, resource, basePath, callback)
async.parallelLimit jobs, 5, callback
@_removeExtraneousFiles resources, basePath, (error) =>
return callback(error) if error?
jobs = for resource in resources
do (resource) =>
(callback) => @_writeResourceToDisk(project_id, resource, basePath, callback)
async.parallelLimit jobs, 5, callback
_createDirectory: (basePath, callback = (error) ->) ->
fs.mkdir basePath, (err) ->
if err?
if err.code is 'EEXIST'
return callback()
else
logger.log {err: err, dir:basePath}, "error creating directory"
return callback(err)
else
return callback()
_removeExtraneousFiles: (resources, basePath, _callback = (error) ->) ->
timer = new Metrics.Timer("unlink-output-files")

View file

@ -7,7 +7,7 @@ path = require "path"
describe "ResourceWriter", ->
beforeEach ->
@ResourceWriter = SandboxedModule.require modulePath, requires:
"fs": @fs = {}
"fs": @fs = { mkdir: sinon.stub().callsArg(1) }
"wrench": @wrench = {}
"./UrlCache" : @UrlCache = {}
"mkdirp" : @mkdirp = sinon.stub().callsArg(1)