Add timestamp to files in deleted bucket

This commit is contained in:
Simon Detheridge 2020-03-14 14:11:17 +00:00
parent edf1ce1f7e
commit 58db14456a
4 changed files with 20 additions and 6 deletions

View file

@ -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()

View file

@ -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",

View file

@ -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"
}
}

View file

@ -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
)
})