Merge pull request #615 from sharelatex/bg-fix-locking-for-copy-project

add missing locking to copyFileFromExistingProject
This commit is contained in:
Brian Gough 2018-05-31 15:52:19 +01:00 committed by GitHub
commit 853d0ab108

View file

@ -45,13 +45,12 @@ wrapWithLock = (methodWithoutLock) ->
methodWithLock
module.exports = ProjectEntityUpdateHandler = self =
# this doesn't need any locking because it's only called by ProjectDuplicator
copyFileFromExistingProjectWithProject: (project, folder_id, originalProject_id, origonalFileRef, userId, callback = (error, fileRef, folder_id) ->)->
copyFileFromExistingProjectWithProject: wrapWithLock
beforeLock: (next) ->
(project, folder_id, originalProject_id, origonalFileRef, userId, callback = (error, fileRef, folder_id) ->)->
project_id = project._id
projectHistoryId = project.overleaf?.history?.id
logger.log { project_id, folder_id, originalProject_id, origonalFileRef }, "copying file in s3 with project"
return callback(err) if err?
ProjectEntityMongoUpdateHandler._confirmFolder project, folder_id, (folder_id)=>
ProjectEntityMongoUpdateHandler._confirmFolder project, folder_id, (folder_id) ->
if !origonalFileRef?
logger.err { project_id, folder_id, originalProject_id, origonalFileRef }, "file trying to copy is null"
return callback()
@ -61,7 +60,11 @@ module.exports = ProjectEntityUpdateHandler = self =
if err?
logger.err { err, project_id, folder_id, originalProject_id, origonalFileRef }, "error coping file in s3"
return callback(err)
ProjectEntityMongoUpdateHandler._putElement project, folder_id, fileRef, "file", (err, result)=>
next(project, folder_id, originalProject_id, origonalFileRef, userId, fileRef, fileStoreUrl, callback)
withLock: (project, folder_id, originalProject_id, origonalFileRef, userId, fileRef, fileStoreUrl, callback = (error, fileRef, folder_id) ->)->
project_id = project._id
projectHistoryId = project.overleaf?.history?.id
ProjectEntityMongoUpdateHandler._putElement project, folder_id, fileRef, "file", (err, result, newProject) ->
if err?
logger.err { err, project_id, folder_id }, "error putting element as part of copy"
return callback(err)
@ -73,7 +76,7 @@ module.exports = ProjectEntityUpdateHandler = self =
path: result?.path?.fileSystem
url: fileStoreUrl
]
DocumentUpdaterHandler.updateProjectStructure project_id, projectHistoryId, userId, {newFiles}, (error) ->
DocumentUpdaterHandler.updateProjectStructure project_id, projectHistoryId, userId, {newFiles, newProject}, (error) ->
return callback(error) if error?
callback null, fileRef, folder_id