@@ -18,17 +18,23 @@ export class Cp {
18
18
* @param {string } containerName - The name of the container in the pod to exec the command inside.
19
19
* @param {string } srcPath - The source path in the pod
20
20
* @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
21
22
*/
22
23
public async cpFromPod (
23
24
namespace : string ,
24
25
podName : string ,
25
26
containerName : string ,
26
27
srcPath : string ,
27
28
tgtPath : string ,
29
+ cwd ?: string ,
28
30
) : Promise < void > {
29
31
const tmpFile = tmp . fileSync ( ) ;
30
32
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 ) ;
32
38
const writerStream = fs . createWriteStream ( tmpFileName ) ;
33
39
const errStream = new WritableStreamBuffer ( ) ;
34
40
this . execInstance . exec (
@@ -59,20 +65,23 @@ export class Cp {
59
65
* @param {string } containerName - The name of the container in the pod to exec the command inside.
60
66
* @param {string } srcPath - The source path in local
61
67
* @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
62
69
*/
63
70
public async cpToPod (
64
71
namespace : string ,
65
72
podName : string ,
66
73
containerName : string ,
67
74
srcPath : string ,
68
75
tgtPath : string ,
76
+ cwd ?: string ,
69
77
) : Promise < void > {
70
78
const tmpFile = tmp . fileSync ( ) ;
71
79
const tmpFileName = tmpFile . name ;
72
80
const command = [ 'tar' , 'xf' , '-' , '-C' , tgtPath ] ;
73
81
await tar . c (
74
82
{
75
83
file : tmpFile . name ,
84
+ cwd,
76
85
} ,
77
86
[ srcPath ] ,
78
87
) ;
0 commit comments