Skip to content

Commit 2bb4ab7

Browse files
feat: allow to set the cwd in copyFromPod for use in tar
1 parent 998e631 commit 2bb4ab7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/cp.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,23 @@ export class Cp {
1818
* @param {string} containerName - The name of the container in the pod to exec the command inside.
1919
* @param {string} srcPath - The source path in the pod
2020
* @param {string} tgtPath - The target path in local
21+
* @param {string} cwd - The directory that is used as the parent in the pod when downloading
2122
*/
2223
public async cpFromPod(
2324
namespace: string,
2425
podName: string,
2526
containerName: string,
2627
srcPath: string,
2728
tgtPath: string,
29+
cwd?: string,
2830
): Promise<void> {
2931
const tmpFile = tmp.fileSync();
3032
const tmpFileName = tmpFile.name;
31-
const command = ['tar', 'zcf', '-', srcPath];
33+
const command = ['tar', 'zcf', '-'];
34+
if (cwd) {
35+
command.push('-C', cwd);
36+
}
37+
command.push(srcPath);
3238
const writerStream = fs.createWriteStream(tmpFileName);
3339
const errStream = new WritableStreamBuffer();
3440
this.execInstance.exec(
@@ -59,7 +65,7 @@ export class Cp {
5965
* @param {string} containerName - The name of the container in the pod to exec the command inside.
6066
* @param {string} srcPath - The source path in local
6167
* @param {string} tgtPath - The target path in the pod
62-
* @param {string} cwd - The directory that is used as the parent when uploading
68+
* @param {string} cwd - The directory that is used as the parent in the host when uploading
6369
*/
6470
public async cpToPod(
6571
namespace: string,

0 commit comments

Comments
 (0)