mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
always create project directory when syncing resources to disk
avoids errors when project is empty
This commit is contained in:
parent
308ca01b3c
commit
26e94f2549
2 changed files with 19 additions and 6 deletions
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue