Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/storage/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
replacedObjectField,
} from './events'
import {
isValidKey,
MAX_OBJECTS_PER_DELETE_BATCH,
MAX_OBJECTS_PER_LOOKUP_BATCH,
mustBeValidKey,
Expand Down Expand Up @@ -615,7 +616,11 @@ export class ObjectStorage {
}

if (versionId === undefined) {
return lockAndRead()
const locked = await lockAndRead()
if (!locked.obj && !isValidKey(objectName)) {
throw ERRORS.NoSuchKey(objectName)
}
return locked
}

const peeked = await superUserDb.findObject(
Expand Down Expand Up @@ -729,7 +734,9 @@ export class ObjectStorage {
versioningStatus,
plainObjects,
versionedObjects,
missingPlainNames: targets.plainNames.filter((name) => !plainObjects.has(name)),
missingPlainNames: targets.plainNames.filter(
(name) => !plainObjects.has(name) && isValidKey(name)
),
}
}

Expand Down
27 changes: 27 additions & 0 deletions src/test/object-versioning-writes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,33 @@ describe('object versioning - version-aware writes', () => {
}
)

it.each([
['ENABLED', ''],
['ENABLED', 'bad{key}.txt'],
['SUSPENDED', ''],
['SUSPENDED', 'bad{key}.txt'],
] as const)(
'%s: deleting the missing invalid key %j writes no delete marker',
async (status, name) => {
await tHelper.database.createBucket({
id: bucketId,
name: bucketId,
versioning_status: 'ENABLED',
})
if (status === 'SUSPENDED') {
await tHelper.database.updateBucket(bucketId, { versioning_status: status })
}

await expect(tHelper.storage.from(bucketId).deleteObject(name)).rejects.toMatchObject({
code: ErrorCode.NoSuchKey,
})
const deleted = await tHelper.storage.from(bucketId).deleteObjects([name, objectName])

expect(deleted.map((object) => object.name)).toEqual([objectName])
expect(await allRowsFor(name)).toEqual([])
}
)

it('deleting a non-current version does not wait for the key lock', async () => {
await tHelper.database.createBucket({
id: bucketId,
Expand Down