fix parameter orders, add S3 rmtree()

This commit is contained in:
Nicolas Raynaud
2020-11-16 18:26:28 +01:00
parent 01ceed9e99
commit 6e2396e5f4
3 changed files with 26 additions and 3 deletions

View File

@@ -281,4 +281,26 @@ export default class S3Handler extends RemoteHandlerAbstract {
}
async _closeFile(fd) {}
// https://stackoverflow.com/a/48955582/72637
async _rmtree(dir) {
const listParams = {
Bucket: this._bucket,
Prefix: this._dir + dir
}
let listedObjects = {}
do {
listedObjects = await this._s3.listObjectsV2({
...listParams,
ContinuationToken: listedObjects.NextContinuationToken
}).promise()
if (listedObjects.Contents.length === 0) {
return
}
await this._s3.deleteObjects({
Bucket: this._bucket,
Delete: { Objects: listedObjects.Contents.map(({ Key }) => ({ Key })) }
}).promise()
} while (listedObjects.IsTruncated)
}
}

View File

@@ -604,7 +604,7 @@ export default class {
try {
await Promise.all([
handler.outputStream(backupFullPath, sizeStream),
handler.outputStream(sizeStream, backupFullPath),
stream.task,
])
} catch (error) {
@@ -858,7 +858,7 @@ export default class {
sourceStream.pipe(sizeStream)
await Promise.all([sourceStream.task, handler.outputStream(file, sizeStream)])
await Promise.all([sourceStream.task, handler.outputStream(sizeStream, file)])
return {
transferSize: sizeStream.size,

View File

@@ -352,8 +352,9 @@ export default class metadataBackup {
try {
await waitAll([
(async () => {
console.log('fileName', fileName)
return timeout.call(
handler.outputStream(fileName, stream).catch(error => {
handler.outputStream(stream, fileName).catch(error => {
stream.destroy()
if (error.message !== 'aborted') {
throw error