1
1
import * as fs from 'fs' ;
2
2
import { WritableStreamBuffer } from 'stream-buffers' ;
3
3
import * as tar from 'tar' ;
4
- import * as tmp from 'tmp-promise' ;
5
-
6
4
import { KubeConfig } from './config' ;
7
5
import { Exec } from './exec' ;
6
+ import { generateTmpFileName } from './util' ;
8
7
9
8
export class Cp {
10
9
public execInstance : Exec ;
@@ -18,7 +17,7 @@ export class Cp {
18
17
* @param {string } containerName - The name of the container in the pod to exec the command inside.
19
18
* @param {string } srcPath - The source path in the pod
20
19
* @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
20
+ * @param {string } [ cwd] - The directory that is used as the parent in the pod when downloading
22
21
*/
23
22
public async cpFromPod (
24
23
namespace : string ,
@@ -28,8 +27,7 @@ export class Cp {
28
27
tgtPath : string ,
29
28
cwd ?: string ,
30
29
) : Promise < void > {
31
- const tmpFile = tmp . fileSync ( ) ;
32
- const tmpFileName = tmpFile . name ;
30
+ const tmpFileName = await generateTmpFileName ( ) ;
33
31
const command = [ 'tar' , 'zcf' , '-' ] ;
34
32
if ( cwd ) {
35
33
command . push ( '-C' , cwd ) ;
@@ -65,7 +63,7 @@ export class Cp {
65
63
* @param {string } containerName - The name of the container in the pod to exec the command inside.
66
64
* @param {string } srcPath - The source path in local
67
65
* @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
66
+ * @param {string } [ cwd] - The directory that is used as the parent in the host when uploading
69
67
*/
70
68
public async cpToPod (
71
69
namespace : string ,
@@ -75,16 +73,9 @@ export class Cp {
75
73
tgtPath : string ,
76
74
cwd ?: string ,
77
75
) : Promise < void > {
78
- const tmpFile = tmp . fileSync ( ) ;
79
- const tmpFileName = tmpFile . name ;
76
+ const tmpFileName = await generateTmpFileName ( ) ;
80
77
const command = [ 'tar' , 'xf' , '-' , '-C' , tgtPath ] ;
81
- await tar . c (
82
- {
83
- file : tmpFile . name ,
84
- cwd,
85
- } ,
86
- [ srcPath ] ,
87
- ) ;
78
+ await tar . c ( { file : tmpFileName , cwd } , [ srcPath ] ) ;
88
79
const readStream = fs . createReadStream ( tmpFileName ) ;
89
80
const errStream = new WritableStreamBuffer ( ) ;
90
81
this . execInstance . exec (
0 commit comments