From 58db14456a02745fb13fc6a6f8182d9644da7d13 Mon Sep 17 00:00:00 2001 From: Simon Detheridge Date: Sat, 14 Mar 2020 14:11:17 +0000 Subject: [PATCH] Add timestamp to files in deleted bucket --- services/filestore/app/js/GcsPersistor.js | 6 +++--- services/filestore/package-lock.json | 6 ++++++ services/filestore/package.json | 3 ++- .../filestore/test/acceptance/js/FilestoreTests.js | 11 +++++++++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/services/filestore/app/js/GcsPersistor.js b/services/filestore/app/js/GcsPersistor.js index d8639e70d4..29286ef505 100644 --- a/services/filestore/app/js/GcsPersistor.js +++ b/services/filestore/app/js/GcsPersistor.js @@ -184,9 +184,9 @@ async function deleteFile(bucketName, key) { } if (settings.filestore.gcs.deletedBucketSuffix) { await file.copy( - storage.bucket( - `${bucketName}${settings.filestore.gcs.deletedBucketSuffix}` - ) + storage + .bucket(`${bucketName}${settings.filestore.gcs.deletedBucketSuffix}`) + .file(`${key}-${new Date()}`) ) } await file.delete() diff --git a/services/filestore/package-lock.json b/services/filestore/package-lock.json index f9d1b1696b..7c21d9e128 100644 --- a/services/filestore/package-lock.json +++ b/services/filestore/package-lock.json @@ -5582,6 +5582,12 @@ "readable-stream": "2 || 3" } }, + "timekeeper": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/timekeeper/-/timekeeper-2.2.0.tgz", + "integrity": "sha512-W3AmPTJWZkRwu+iSNxPIsLZ2ByADsOLbbLxe46UJyWj3mlYLlwucKiq+/dPm0l9wTzqoF3/2PH0AGFCebjq23A==", + "dev": true + }, "tiny-async-pool": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/tiny-async-pool/-/tiny-async-pool-1.1.0.tgz", diff --git a/services/filestore/package.json b/services/filestore/package.json index 73459bac71..51530e86b4 100644 --- a/services/filestore/package.json +++ b/services/filestore/package.json @@ -63,6 +63,7 @@ "sandboxed-module": "2.0.3", "sinon": "7.1.1", "sinon-chai": "^3.3.0", - "streamifier": "^0.1.1" + "streamifier": "^0.1.1", + "timekeeper": "^2.2.0" } } diff --git a/services/filestore/test/acceptance/js/FilestoreTests.js b/services/filestore/test/acceptance/js/FilestoreTests.js index 0aa2c8e294..8369698891 100644 --- a/services/filestore/test/acceptance/js/FilestoreTests.js +++ b/services/filestore/test/acceptance/js/FilestoreTests.js @@ -16,6 +16,7 @@ const { Storage } = require('@google-cloud/storage') const streamifier = require('streamifier') chai.use(require('chai-as-promised')) const { ObjectId } = require('mongodb') +const tk = require('timekeeper') const fsWriteFile = promisify(fs.writeFile) const fsStat = promisify(fs.stat) @@ -388,9 +389,11 @@ describe('Filestore', function() { if (backend === 'GcsPersistor') { describe('when deleting a file in GCS', function() { - let fileId, fileUrl, content, error + let fileId, fileUrl, content, error, date beforeEach(async function() { + date = new Date() + tk.freeze(date) fileId = ObjectId() fileUrl = `${filestoreUrl}/project/${projectId}/file/${fileId}` @@ -409,6 +412,10 @@ describe('Filestore', function() { } }) + afterEach(function() { + tk.reset() + }) + it('should not throw an error', function() { expect(error).not.to.exist }) @@ -417,7 +424,7 @@ describe('Filestore', function() { await TestHelper.expectPersistorToHaveFile( app.persistor, `${Settings.filestore.stores.user_files}-deleted`, - `${projectId}/${fileId}`, + `${projectId}/${fileId}-${date}`, content ) })