From 2bb4ab70ce92caca1c58fd411e1042625a533fa8 Mon Sep 17 00:00:00 2001 From: Sayak Mukhopadhyay Date: Wed, 15 Feb 2023 13:46:33 +0530 Subject: [PATCH] feat: allow to set the cwd in `copyFromPod` for use in tar --- src/cp.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cp.ts b/src/cp.ts index 9122614a30..0327ef4187 100644 --- a/src/cp.ts +++ b/src/cp.ts @@ -18,6 +18,7 @@ export class Cp { * @param {string} containerName - The name of the container in the pod to exec the command inside. * @param {string} srcPath - The source path in the pod * @param {string} tgtPath - The target path in local + * @param {string} cwd - The directory that is used as the parent in the pod when downloading */ public async cpFromPod( namespace: string, @@ -25,10 +26,15 @@ export class Cp { containerName: string, srcPath: string, tgtPath: string, + cwd?: string, ): Promise { const tmpFile = tmp.fileSync(); const tmpFileName = tmpFile.name; - const command = ['tar', 'zcf', '-', srcPath]; + const command = ['tar', 'zcf', '-']; + if (cwd) { + command.push('-C', cwd); + } + command.push(srcPath); const writerStream = fs.createWriteStream(tmpFileName); const errStream = new WritableStreamBuffer(); this.execInstance.exec( @@ -59,7 +65,7 @@ export class Cp { * @param {string} containerName - The name of the container in the pod to exec the command inside. * @param {string} srcPath - The source path in local * @param {string} tgtPath - The target path in the pod - * @param {string} cwd - The directory that is used as the parent when uploading + * @param {string} cwd - The directory that is used as the parent in the host when uploading */ public async cpToPod( namespace: string,