Skip to content

Commit d3ed6dd

Browse files
authored
Merge pull request #989 from SayakMukhopadhyay/fix-987
feat: allow to set the cwd in `copyToPod` for use in tar
2 parents 243ebb8 + 2bb4ab7 commit d3ed6dd

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/cp.ts

Lines changed: 10 additions & 1 deletion
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,20 +65,23 @@ 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
68+
* @param {string} cwd - The directory that is used as the parent in the host when uploading
6269
*/
6370
public async cpToPod(
6471
namespace: string,
6572
podName: string,
6673
containerName: string,
6774
srcPath: string,
6875
tgtPath: string,
76+
cwd?: string,
6977
): Promise<void> {
7078
const tmpFile = tmp.fileSync();
7179
const tmpFileName = tmpFile.name;
7280
const command = ['tar', 'xf', '-', '-C', tgtPath];
7381
await tar.c(
7482
{
7583
file: tmpFile.name,
84+
cwd,
7685
},
7786
[srcPath],
7887
);

0 commit comments

Comments
 (0)