Skip to content
Merged
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
13 changes: 12 additions & 1 deletion lib/s3/s3.disk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,18 @@ export class S3Disk extends StorageDisk {
const signal = options?.signal;
if (!this.batchDelete || keys.length === 1) {
for (const key of keys) {
await this.send({ operation: 'DeleteObject', method: 'DELETE', key: this.prefix + key, signal });
// S3 answers 204 for a missing key; Google Cloud Storage answers 404 NoSuchKey
await this.send({
operation: 'DeleteObject',
method: 'DELETE',
key: this.prefix + key,
notFoundKey: key,
signal,
}).catch((error: unknown) => {
if (!(error instanceof StorageFileNotFoundError)) {
throw error;
}
});
}
return;
}
Expand Down
10 changes: 10 additions & 0 deletions tests/s3-responses.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,16 @@ describe('S3Disk requests', () => {
expect(calls.map((c) => `${c.method} ${c.url.pathname}${c.url.search}`)).toEqual(['DELETE /shop/only.txt']);
});

it('a DeleteObject that answers 404 NoSuchKey (Google Cloud Storage) is not an error', async () => {
const { disk: s3, calls } = disk(() => s3Error(404, 'NoSuchKey'), { batchDelete: false });
await expect(s3.delete('gone.txt')).resolves.toBeUndefined();
await expect(s3.delete(['a.txt', 'b.txt'])).resolves.toBeUndefined();
expect(calls).toHaveLength(3);

const noBucket = disk(() => s3Error(404, 'NoSuchBucket'));
await expect(noBucket.disk.delete('a.txt')).rejects.toMatchObject({ code: 'NoSuchBucket' });
});

it('deletes several keys in one quiet DeleteObjects with escaped, prefixed keys and a matching Content-MD5', async () => {
const { disk: s3, calls } = disk(() => xml('<DeleteResult></DeleteResult>'), { prefix: 'p/' });
await s3.delete(['a&b.txt', '<c>.txt']);
Expand Down
Loading