Merge pull request #1511 from sharelatex/as-inc-linked-file-rev

Increment rev of linked file to fix bug where dropbox not syncing

GitOrigin-RevId: 6779d10f9ed64eeca901590cc888f35382a2b284
This commit is contained in:
Brian Gough 2019-02-18 13:24:46 +00:00 committed by James Allen
parent e379691767
commit 2ab346e762
4 changed files with 12 additions and 6 deletions

View file

@ -63,7 +63,7 @@ module.exports = ProjectEntityMongoUpdateHandler = self =
set["#{path.mongo}._id"] = newFileRef._id
set["#{path.mongo}.created"] = new Date()
set["#{path.mongo}.linkedFileData"] = newFileRef.linkedFileData
set["#{path.mongo}.rev"] = 1
inc["#{path.mongo}.rev"] = 1
update =
"$inc": inc
"$set": set

View file

@ -233,7 +233,13 @@ module.exports = ProjectEntityUpdateHandler = self =
url: fileStoreUrl
]
projectHistoryId = project.overleaf?.history?.id
TpdsUpdateSender.addFile {project_id:project._id, file_id:newFileRef._id, path:path.fileSystem, rev:newFileRef.rev+1, project_name:project.name}, (err) ->
# Increment the rev for an in-place update (with the same path) so the third-party-datastore
# knows this is a new file.
# Ideally we would get this from ProjectEntityMongoUpdateHandler.replaceFileWithNew
# but it returns the original oldFileRef (after incrementing the rev value in mongo),
# so we add 1 to the rev from that. This isn't atomic and relies on the lock
# but it is acceptable for now.
TpdsUpdateSender.addFile {project_id:project._id, file_id:newFileRef._id, path:path.fileSystem, rev:oldFileRef.rev + 1, project_name:project.name}, (err) ->
return callback(err) if err?
DocumentUpdaterHandler.updateProjectStructure project_id, projectHistoryId, userId, {oldFiles, newFiles}, callback

View file

@ -135,8 +135,8 @@ describe 'ProjectEntityMongoUpdateHandler', ->
.calledWith(
{ _id: project_id },
{
'$inc': { 'version': 1 }
'$set': { 'file.png._id': @newFile._id, 'file.png.created': new Date(), 'file.png.linkedFileData': @linkedFileData, 'file.png.rev': 1 }
'$inc': { 'version': 1, 'file.png.rev': 1 }
'$set': { 'file.png._id': @newFile._id, 'file.png.created': new Date(), 'file.png.linkedFileData': @linkedFileData }
}
{}
)

View file

@ -391,7 +391,7 @@ describe 'ProjectEntityUpdateHandler', ->
@FileStoreHandler.uploadFileFromDisk = sinon.stub().yields(null, @newFileUrl)
@newFile = _id: new_file_id, name: "dummy-upload-filename", rev: 0, linkedFileData: @linkedFileData
@oldFile = _id: file_id
@oldFile = _id: file_id, rev: 3
@path = "/path/to/file"
@ProjectEntityMongoUpdateHandler._insertDeletedFileReference = sinon.stub().yields()
@ProjectEntityMongoUpdateHandler.replaceFileWithNew = sinon.stub().yields(null, @oldFile, @project, fileSystem: @path)
@ -413,7 +413,7 @@ describe 'ProjectEntityUpdateHandler', ->
project_id: project_id
project_name: @project.name
file_id: new_file_id
rev: @newFile.rev + 1
rev: @oldFile.rev + 1
path: @path
})
.should.equal true