Merge pull request #22327 from overleaf/bg-fix-copy-blob

fix bug that prevents copying blobs between different backends in history-v1

GitOrigin-RevId: 41140ad42d0d7c1beda83e588649127c22603dec
This commit is contained in:
Brian Gough 2024-12-04 19:00:24 +00:00 committed by Copybot
parent c4e0294d36
commit 104ae341b1
3 changed files with 40 additions and 4 deletions

View file

@ -206,7 +206,7 @@ exports.paths = {
name: 'copyFrom',
in: 'query',
description: 'source project id',
required: false,
required: true,
type: 'string',
},
],

View file

@ -405,10 +405,11 @@ class BlobStore {
const sourceProjectId = this.projectId
const { bucket, key: sourceKey } = getBlobLocation(sourceProjectId, hash)
const destKey = makeProjectKey(targetProjectId, hash)
const targetBackend = getBackend(targetProjectId)
logger.debug({ sourceProjectId, targetProjectId, hash }, 'copyBlob started')
try {
await persistor.copyObject(bucket, sourceKey, destKey)
await this.backend.insertBlob(targetProjectId, sourceBlob)
await targetBackend.insertBlob(targetProjectId, sourceBlob)
} finally {
logger.debug(
{ sourceProjectId, targetProjectId, hash },

View file

@ -480,7 +480,7 @@ describe('BlobStore', function () {
})
describe('copyBlob method', function () {
it('copies a binary blob to another project', async function () {
it('copies a binary blob to another project in the same backend', async function () {
const testFile = 'graph.png'
const originalHash = testFiles.GRAPH_PNG_HASH
const insertedBlob = await blobStore.putFile(testFiles.path(testFile))
@ -493,7 +493,7 @@ describe('BlobStore', function () {
expect(copiedBlob.getStringLength()).to.be.null
})
it('copies a text blob to another project', async function () {
it('copies a text blob to another project in the same backend', async function () {
const insertedBlob = await blobStore.putString(helloWorldString)
await blobStore.copyBlob(insertedBlob, scenario.projectId2)
const copiedBlob = await blobStore2.getBlob(helloWorldHash)
@ -502,6 +502,41 @@ describe('BlobStore', function () {
expect(content).to.equal(helloWorldString)
})
})
describe('copyBlob method with different backends', function () {
const otherScenario = scenarios.find(
s => s.backend !== scenario.backend
)
const otherBlobStore = new BlobStore(otherScenario.projectId2)
beforeEach(async function () {
await otherBlobStore.initialize()
})
it('copies a binary blob to another project in a different backend', async function () {
const testFile = 'graph.png'
const originalHash = testFiles.GRAPH_PNG_HASH
const insertedBlob = await blobStore.putFile(testFiles.path(testFile))
await blobStore.copyBlob(insertedBlob, otherScenario.projectId2)
const copiedBlob = await otherBlobStore.getBlob(originalHash)
expect(copiedBlob).to.exist
expect(copiedBlob.getHash()).to.equal(originalHash)
expect(copiedBlob.getByteLength()).to.equal(
insertedBlob.getByteLength()
)
expect(copiedBlob.getStringLength()).to.be.null
})
it('copies a text blob to another project in a different backend', async function () {
const insertedBlob = await blobStore.putString(helloWorldString)
await blobStore.copyBlob(insertedBlob, otherScenario.projectId2)
const copiedBlob = await otherBlobStore.getBlob(helloWorldHash)
expect(copiedBlob).to.exist
expect(copiedBlob.getHash()).to.equal(helloWorldHash)
const content = await otherBlobStore.getString(helloWorldHash)
expect(content).to.equal(helloWorldString)
})
})
})
}