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 =
|
module.exports = ResourceWriter =
|
||||||
syncResourcesToDisk: (project_id, resources, basePath, callback = (error) ->) ->
|
syncResourcesToDisk: (project_id, resources, basePath, callback = (error) ->) ->
|
||||||
@_removeExtraneousFiles resources, basePath, (error) =>
|
@_createDirectory basePath, (error) =>
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
jobs = for resource in resources
|
@_removeExtraneousFiles resources, basePath, (error) =>
|
||||||
do (resource) =>
|
return callback(error) if error?
|
||||||
(callback) => @_writeResourceToDisk(project_id, resource, basePath, callback)
|
jobs = for resource in resources
|
||||||
async.parallelLimit jobs, 5, callback
|
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) ->) ->
|
_removeExtraneousFiles: (resources, basePath, _callback = (error) ->) ->
|
||||||
timer = new Metrics.Timer("unlink-output-files")
|
timer = new Metrics.Timer("unlink-output-files")
|
||||||
|
|
|
@ -7,7 +7,7 @@ path = require "path"
|
||||||
describe "ResourceWriter", ->
|
describe "ResourceWriter", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@ResourceWriter = SandboxedModule.require modulePath, requires:
|
@ResourceWriter = SandboxedModule.require modulePath, requires:
|
||||||
"fs": @fs = {}
|
"fs": @fs = { mkdir: sinon.stub().callsArg(1) }
|
||||||
"wrench": @wrench = {}
|
"wrench": @wrench = {}
|
||||||
"./UrlCache" : @UrlCache = {}
|
"./UrlCache" : @UrlCache = {}
|
||||||
"mkdirp" : @mkdirp = sinon.stub().callsArg(1)
|
"mkdirp" : @mkdirp = sinon.stub().callsArg(1)
|
||||||
|
|
Loading…
Reference in a new issue