Ensure the dirname is not affected when we rename an entity

Fixes https://github.com/sharelatex/web-sharelatex-internal/issues/93
This commit is contained in:
Alberto Fernández Capel
2017-12-22 14:24:00 +00:00
parent 18ae27fd66
commit bf324b5e04
2 changed files with 7 additions and 12 deletions
@@ -456,14 +456,14 @@ module.exports = ProjectEntityHandler =
return callback(error) if error?
ProjectEntityHandler.getAllEntitiesFromProject project, (error, oldDocs, oldFiles) =>
return callback(error) if error?
projectLocator.findElement {project:project, element_id:entity_id, type:entityType}, (error, entity, path)=>
projectLocator.findElement {project:project, element_id:entity_id, type:entityType}, (error, entity, entPath)=>
return callback(error) if error?
endPath = path.fileSystem.replace(entity.name, newName)
endPath = path.join(path.dirname(entPath.fileSystem), newName)
conditions = {_id:project_id}
update = "$set":{}
namePath = path.mongo+".name"
namePath = entPath.mongo+".name"
update["$set"][namePath] = newName
tpdsUpdateSender.moveEntity({project_id:project_id, startPath:path.fileSystem, endPath:endPath, project_name:project.name, rev:entity.rev})
tpdsUpdateSender.moveEntity({project_id:project_id, startPath:entPath.fileSystem, endPath:endPath, project_name:project.name, rev:entity.rev})
Project.findOneAndUpdate conditions, update, { "new": true}, (error, newProject) ->
return callback(error) if error?
ProjectEntityHandler.getAllEntitiesFromProject newProject, (error, newDocs, newFiles) =>