From 6825b2e3fc2a22086b66c9a189ff558d9d95bfa6 Mon Sep 17 00:00:00 2001 From: Hong Phuc Nguyen Date: Thu, 5 Jan 2023 15:54:10 +0700 Subject: [PATCH] Doing sanitizeKey when doing deleteFile(s) (#9209) * Doing sanitizeKey when doing deleteFile(s) Doing sanitizeKey when doing deleteFile(s). In case of backup file name in backups bucket backup-2023-01-03T185512.686Z.tar.gz but in global-db store backup filename is backup-2023-01-03T18:55:12.686Z.tar.gz sanitizeKey on deleteFile(s) method will prevent all other case related to this bug * use .promise() instead callback for workaround aws-sdk bug --- packages/backend-core/src/objectStore/objectStore.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/backend-core/src/objectStore/objectStore.ts b/packages/backend-core/src/objectStore/objectStore.ts index 1cc8ad3add..f601d40a37 100644 --- a/packages/backend-core/src/objectStore/objectStore.ts +++ b/packages/backend-core/src/objectStore/objectStore.ts @@ -329,9 +329,9 @@ export const deleteFile = async (bucketName: string, filepath: string) => { await makeSureBucketExists(objectStore, bucketName) const params = { Bucket: bucketName, - Key: filepath, + Key: sanitizeKey(filepath), } - return objectStore.deleteObject(params) + return objectStore.deleteObject(params).promise() } export const deleteFiles = async (bucketName: string, filepaths: string[]) => { @@ -340,7 +340,7 @@ export const deleteFiles = async (bucketName: string, filepaths: string[]) => { const params = { Bucket: bucketName, Delete: { - Objects: filepaths.map((path: any) => ({ Key: path })), + Objects: filepaths.map((path: any) => ({ Key: sanitizeKey(path) })), }, } return objectStore.deleteObjects(params).promise()