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