Merge pull request #11179 from overleaf/em-upgrade-gcs-lib

Upgrade @google-cloud/storage library to 6.9.0

GitOrigin-RevId: 0e80dcccca4679ffe28d5b16512a691e58694e2b
This commit is contained in:
Eric Mc Sween 2023-01-17 07:44:43 -05:00 committed by Copybot
parent f97a543d41
commit 4325f1d947
6 changed files with 285 additions and 1210 deletions

View file

@ -22,7 +22,7 @@
"@overleaf/logger": "*"
},
"dependencies": {
"@google-cloud/storage": "~5.1.2",
"@google-cloud/storage": "^6.9.0",
"@overleaf/o-error": "*",
"aws-sdk": "^2.718.0",
"fast-crc32c": "https://github.com/overleaf/node-fast-crc32c/archive/aae6b2a4c7a7a159395df9cc6c38dfde702d6f51.tar.gz",

View file

@ -213,7 +213,8 @@ module.exports = class GcsPersistor extends AbstractPersistor {
}
async deleteDirectory(bucketName, key) {
let query = { directory: key, autoPaginate: false }
const prefix = ensurePrefixIsDirectory(key)
let query = { prefix, autoPaginate: false }
do {
try {
const [files, nextQuery] = await this.storage
@ -247,11 +248,12 @@ module.exports = class GcsPersistor extends AbstractPersistor {
async directorySize(bucketName, key) {
let files
const prefix = ensurePrefixIsDirectory(key)
try {
const [response] = await this.storage
.bucket(bucketName)
.getFiles({ directory: key })
.getFiles({ prefix })
files = response
} catch (err) {
throw PersistorHelper.wrapError(
@ -301,3 +303,7 @@ module.exports = class GcsPersistor extends AbstractPersistor {
}
}
}
function ensurePrefixIsDirectory(key) {
return key === '' || key.endsWith('/') ? key : `${key}/`
}

View file

@ -554,12 +554,13 @@ describe('GcsPersistorTests', function () {
describe('deleteDirectory', function () {
const directoryName = `${ObjectId()}/${ObjectId()}`
const directoryPrefix = `${directoryName}/`
describe('with valid parameters', function () {
beforeEach(async function () {
GcsBucket.getFiles = sinon.stub()
// set up multiple paginated calls to getFiles
GcsBucket.getFiles
.withArgs({ directory: directoryName, autoPaginate: false })
.withArgs({ prefix: directoryPrefix, autoPaginate: false })
.resolves([['aaa', 'bbb'], 'call-1'])
GcsBucket.getFiles
.withArgs('call-1')
@ -571,7 +572,7 @@ describe('GcsPersistorTests', function () {
it('should list the objects in the directory', function () {
expect(Storage.prototype.bucket).to.have.been.calledWith(bucket)
expect(GcsBucket.getFiles).to.have.been.calledWith({
directory: directoryName,
prefix: directoryPrefix,
autoPaginate: false,
})
expect(GcsBucket.getFiles).to.have.been.calledWith('call-1')
@ -615,7 +616,9 @@ describe('GcsPersistorTests', function () {
it('should list the objects in the directory', function () {
expect(Storage.prototype.bucket).to.have.been.calledWith(bucket)
expect(GcsBucket.getFiles).to.have.been.calledWith({ directory: key })
expect(GcsBucket.getFiles).to.have.been.calledWith({
prefix: `${key}/`,
})
})
it('should return the directory size', function () {
@ -633,7 +636,9 @@ describe('GcsPersistorTests', function () {
it('should list the objects in the directory', function () {
expect(Storage.prototype.bucket).to.have.been.calledWith(bucket)
expect(GcsBucket.getFiles).to.have.been.calledWith({ directory: key })
expect(GcsBucket.getFiles).to.have.been.calledWith({
prefix: `${key}/`,
})
})
it('should return zero', function () {

1468
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -34,7 +34,7 @@
"streamifier": "^0.1.1"
},
"devDependencies": {
"@google-cloud/storage": "^5.1.2",
"@google-cloud/storage": "^6.9.0",
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",
"mocha": "^10.2.0",

View file

@ -35,7 +35,7 @@
"tiny-async-pool": "^1.1.0"
},
"devDependencies": {
"@google-cloud/storage": "^5.1.2",
"@google-cloud/storage": "^6.9.0",
"aws-sdk": "^2.718.0",
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",