From 270791b8ea73bad33abc3d9f78e5b91dfeacae24 Mon Sep 17 00:00:00 2001 From: Matthew Smith Date: Tue, 4 Jun 2019 16:14:01 -0400 Subject: [PATCH] skip cleanup of files that don't match the regex --- deploy/lib/cleanupDeploymentBucket.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/deploy/lib/cleanupDeploymentBucket.js b/deploy/lib/cleanupDeploymentBucket.js index c5084d4..6a51b2a 100644 --- a/deploy/lib/cleanupDeploymentBucket.js +++ b/deploy/lib/cleanupDeploymentBucket.js @@ -21,14 +21,25 @@ module.exports = { const files = response.items; - // 4 old ones + the one which will be uploaded after the cleanup = 5 - const objectsToKeepCount = 4; + const oldFileRegex = /(serverless)\/(.+)\/(.+)\/(\d+)-(.+)\/(.+\.zip)/; + + // filter out files that are in the bucket but don't match files created by the plugin + const filteredFiles = _.filter(files, (file) => { + if (file.name.match(oldFileRegex)) { + // the file matches the ones we want to clean up + return true; + } + return false; + }); - const orderedObjects = _.orderBy(files, (file) => { - const timestamp = file.name.match(/(serverless)\/(.+)\/(.+)\/(\d+)-(.+)\/(.+\.zip)/)[4]; + const orderedObjects = _.orderBy(filteredFiles, (file) => { + const timestamp = file.name.match(oldFileRegex)[4]; return timestamp; }, ['asc']); + // 4 old ones + the one which will be uploaded after the cleanup = 5 + const objectsToKeepCount = 4; + const objectsToKeep = _.takeRight(orderedObjects, objectsToKeepCount); const objectsToRemove = _.pullAllWith(files, objectsToKeep, _.isEqual);