Skip to content

feat: allow to set the cwd in copyToPod for use in tar #989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/cp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,23 @@ 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,
podName: string,
containerName: string,
srcPath: string,
tgtPath: string,
cwd?: string,
): Promise<void> {
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(
Expand Down Expand Up @@ -59,20 +65,23 @@ 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 in the host when uploading
*/
public async cpToPod(
namespace: string,
podName: string,
containerName: string,
srcPath: string,
tgtPath: string,
cwd?: string,
): Promise<void> {
const tmpFile = tmp.fileSync();
const tmpFileName = tmpFile.name;
const command = ['tar', 'xf', '-', '-C', tgtPath];
await tar.c(
{
file: tmpFile.name,
cwd,
},
[srcPath],
);
Expand Down