Merge pull request #1763 from overleaf/bg-preserve-file-hash-on-copy-and-delete

preserve file hash on copy and delete

GitOrigin-RevId: 2dc000255dcfe875a30a7e7f878aaa09fea367dc
This commit is contained in:
Brian Gough 2019-05-15 13:30:47 +01:00 committed by sharelatex
parent 833caf4acd
commit e252c64996
3 changed files with 13 additions and 6 deletions

View file

@ -57,6 +57,8 @@ module.exports = ProjectEntityUpdateHandler = self =
fileProperties = name : SafePath.clean(origonalFileRef.name) fileProperties = name : SafePath.clean(origonalFileRef.name)
if origonalFileRef.linkedFileData? if origonalFileRef.linkedFileData?
fileProperties.linkedFileData = origonalFileRef.linkedFileData fileProperties.linkedFileData = origonalFileRef.linkedFileData
if origonalFileRef.hash?
fileProperties.hash = origonalFileRef.hash
fileRef = new File(fileProperties) fileRef = new File(fileProperties)
FileStoreHandler.copyFile originalProject_id, origonalFileRef._id, project._id, fileRef._id, (err, fileStoreUrl)-> FileStoreHandler.copyFile originalProject_id, origonalFileRef._id, project._id, fileRef._id, (err, fileStoreUrl)->
if err? if err?

View file

@ -13,8 +13,11 @@ DeletedDocSchema = new Schema
name: String name: String
DeletedFileSchema = new Schema DeletedFileSchema = new Schema
name: String name : String
deletedAt: {type: Date} created : type:Date
linkedFileData : { type: Schema.Types.Mixed }
hash : type:String
deletedAt : {type: Date}
ProjectSchema = new Schema ProjectSchema = new Schema
name : {type:String, default:'new project'} name : {type:String, default:'new project'}

View file

@ -44,7 +44,8 @@ describe 'ProjectEntityUpdateHandler', ->
@rev = 0 @rev = 0
if options.linkedFileData? if options.linkedFileData?
@linkedFileData = options.linkedFileData @linkedFileData = options.linkedFileData
if options.hash?
@hash = options.hash
@docName = "doc-name" @docName = "doc-name"
@docLines = ['1234','abc'] @docLines = ['1234','abc']
@ -121,7 +122,7 @@ describe 'ProjectEntityUpdateHandler', ->
.calledWithMatch(project_id, projectHistoryId, userId, changesMatcher) .calledWithMatch(project_id, projectHistoryId, userId, changesMatcher)
.should.equal true .should.equal true
describe 'copyFileFromExistingProjectWithProject, with linkedFileData', -> describe 'copyFileFromExistingProjectWithProject, with linkedFileData and hash', ->
beforeEach -> beforeEach ->
@oldProject_id = "123kljadas" @oldProject_id = "123kljadas"
@ -129,6 +130,7 @@ describe 'ProjectEntityUpdateHandler', ->
_id:"oldFileRef", _id:"oldFileRef",
name:@fileName, name:@fileName,
linkedFileData: @linkedFileData linkedFileData: @linkedFileData
hash: "123456"
} }
@ProjectEntityMongoUpdateHandler._confirmFolder = sinon.stub().yields(folder_id) @ProjectEntityMongoUpdateHandler._confirmFolder = sinon.stub().yields(folder_id)
@ProjectEntityMongoUpdateHandler._putElement = sinon.stub().yields(null, {path:{fileSystem: @fileSystemPath}}) @ProjectEntityMongoUpdateHandler._putElement = sinon.stub().yields(null, {path:{fileSystem: @fileSystemPath}})
@ -140,12 +142,12 @@ describe 'ProjectEntityUpdateHandler', ->
.calledWith(@oldProject_id, @oldFileRef._id, project_id, file_id) .calledWith(@oldProject_id, @oldFileRef._id, project_id, file_id)
.should.equal true .should.equal true
it 'should put file into folder by calling put element, with the linkedFileData', -> it 'should put file into folder by calling put element, with the linkedFileData and hash', ->
@ProjectEntityMongoUpdateHandler._putElement @ProjectEntityMongoUpdateHandler._putElement
.calledWithMatch( .calledWithMatch(
@project, @project,
folder_id, folder_id,
{ _id: file_id, name: @fileName, linkedFileData: @linkedFileData}, { _id: file_id, name: @fileName, linkedFileData: @linkedFileData, hash: "123456"},
"file" "file"
) )
.should.equal true .should.equal true