diff --git a/src/storage/object.ts b/src/storage/object.ts index 33fe8a6c..5a6c0f23 100644 --- a/src/storage/object.ts +++ b/src/storage/object.ts @@ -341,16 +341,8 @@ export class ObjectStorage { return Promise.all([ db.findObject(this.bucketId, sourceObjectName, 'id'), db.updateObject(this.bucketId, sourceObjectName, { - name: sourceObjectName, - version: '1', - owner, - }), - // We also check if we can create the destination object - // before starting the move - db.asSuperUser().createObject({ name: destinationObjectName, version: newVersion, - bucket_id: this.bucketId, owner, }), ]) @@ -372,15 +364,15 @@ export class ObjectStorage { const metadata = await this.backend.headObject(storageS3Bucket, s3DestinationKey, newVersion) await this.db.asSuperUser().withTransaction(async (db) => { - await db.createObject({ + await db.findObject(this.bucketId, sourceObjectName, 'id', { forUpdate: true }) + + await db.updateObject(this.bucketId, sourceObjectName, { name: destinationObjectName, version: newVersion, - bucket_id: this.bucketId, owner: sourceObj.owner, metadata, }) - await db.deleteObject(this.bucketId, sourceObjectName, sourceObj.version) await ObjectAdminDelete.send({ name: sourceObjectName, bucketId: this.bucketId,