diff --git a/src/cp.ts b/src/cp.ts index 2e02bccc04..9ee6dcb6d9 100644 --- a/src/cp.ts +++ b/src/cp.ts @@ -31,7 +31,7 @@ export class Cp { const command = ['tar', 'zcf', '-', srcPath]; const writerStream = fs.createWriteStream(tmpFileName); const errStream = new WritableStreamBuffer(); - this.execInstance.exec( + const conn = await this.execInstance.exec( namespace, podName, containerName, @@ -45,12 +45,18 @@ export class Cp { if (status === 'Failure' || errStream.size()) { throw new Error(`Error from cpFromPod - details: \n ${errStream.getContentsAsString()}`); } - await tar.x({ - file: tmpFileName, - cwd: tgtPath, - }); }, ); + return await new Promise((resolve) => { + conn.addEventListener('close', (event) => { + resolve( + tar.x({ + file: tmpFileName, + cwd: tgtPath, + }), + ); + }); + }); } /** @@ -78,7 +84,7 @@ export class Cp { ); const readStream = fs.createReadStream(tmpFileName); const errStream = new WritableStreamBuffer(); - this.execInstance.exec( + const conn = await this.execInstance.exec( namespace, podName, containerName, @@ -93,5 +99,10 @@ export class Cp { } }, ); + return new Promise((resolve) => { + conn.addEventListener('close', (event) => { + resolve(); + }); + }); } }