From 5886b02e6ada5033f2025ca42af0bc99853574b0 Mon Sep 17 00:00:00 2001 From: Sayak Mukhopadhyay Date: Wed, 15 Feb 2023 11:40:58 +0530 Subject: [PATCH 1/2] fix: resolve copy to pod when the copying is completed --- src/cp.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cp.ts b/src/cp.ts index 2e02bccc04..98479143b2 100644 --- a/src/cp.ts +++ b/src/cp.ts @@ -78,7 +78,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 +93,10 @@ export class Cp { } }, ); + return new Promise((resolve) => { + conn.addEventListener('close', (event) => { + resolve(); + }); + }); } } From 911be676daf004858d45b67e84ec54c62a13fbd9 Mon Sep 17 00:00:00 2001 From: Sayak Mukhopadhyay Date: Wed, 15 Feb 2023 16:22:21 +0530 Subject: [PATCH 2/2] fix: resolve copy from pod when the copying is completed --- src/cp.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/cp.ts b/src/cp.ts index 98479143b2..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, + }), + ); + }); + }); } /**