Skip to content

Commit 2679059

Browse files
committed
♻️ move code to async await to management concurrent delete
Issue: CLDSRV-632
1 parent 0606711 commit 2679059

File tree

1 file changed

+34
-38
lines changed

1 file changed

+34
-38
lines changed

tests/functional/aws-node-sdk/lib/utility/bucket-util.js

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -82,48 +82,44 @@ class BucketUtility {
8282
* @returns {Promise.<T>}
8383
*/
8484

85-
empty(bucketName) {
85+
async empty(bucketName) {
8686
const param = {
8787
Bucket: bucketName,
8888
};
8989

90-
return this.s3
91-
.listObjectVersions(param).promise()
92-
.then(data =>
93-
Promise.all(
94-
data.Versions
95-
.filter(object => !object.Key.endsWith('/'))
96-
// remove all objects
97-
.map(object =>
98-
this.s3.deleteObject({
99-
Bucket: bucketName,
100-
Key: object.Key,
101-
VersionId: object.VersionId,
102-
}).promise()
103-
.then(() => object)
104-
)
105-
.concat(data.Versions
106-
.filter(object => object.Key.endsWith('/'))
107-
// remove all directories
108-
.map(object =>
109-
this.s3.deleteObject({
110-
Bucket: bucketName,
111-
Key: object.Key,
112-
VersionId: object.VersionId,
113-
}).promise()
114-
.then(() => object)
115-
)
116-
)
117-
.concat(data.DeleteMarkers
118-
.map(object =>
119-
this.s3.deleteObject({
120-
Bucket: bucketName,
121-
Key: object.Key,
122-
VersionId: object.VersionId,
123-
}).promise()
124-
.then(() => object)))
125-
)
126-
);
90+
const listedObjects = await this.s3.listObjectVersions(param).promise();
91+
92+
for (const version of listedObjects.Versions) {
93+
if (version.Key.endsWith('/')) {
94+
continue;
95+
}
96+
97+
await this.s3.deleteObject({
98+
Bucket: bucketName,
99+
Key: version.Key,
100+
VersionId: version.VersionId,
101+
}).promise();
102+
}
103+
104+
for (const version of listedObjects.Versions) {
105+
if (!version.Key.endsWith('/')) {
106+
continue;
107+
}
108+
109+
await this.s3.deleteObject({
110+
Bucket: bucketName,
111+
Key: version.Key,
112+
VersionId: version.VersionId,
113+
}).promise();
114+
}
115+
116+
for (const marker of listedObjects.DeleteMarkers) {
117+
await this.s3.deleteObject({
118+
Bucket: bucketName,
119+
Key: marker.Key,
120+
VersionId: marker.VersionId,
121+
}).promise();
122+
}
127123
}
128124

129125
emptyMany(bucketNames) {

0 commit comments

Comments
 (0)