@@ -35,26 +35,33 @@ export class Cp {
35
35
command . push ( srcPath ) ;
36
36
const writerStream = fs . createWriteStream ( tmpFileName ) ;
37
37
const errStream = new WritableStreamBuffer ( ) ;
38
- this . execInstance . exec (
39
- namespace ,
40
- podName ,
41
- containerName ,
42
- command ,
43
- writerStream ,
44
- errStream ,
45
- null ,
46
- false ,
47
- async ( { status } ) => {
48
- writerStream . close ( ) ;
49
- if ( status === 'Failure' || errStream . size ( ) ) {
50
- throw new Error ( `Error from cpFromPod - details: \n ${ errStream . getContentsAsString ( ) } ` ) ;
51
- }
52
- await tar . x ( {
53
- file : tmpFileName ,
54
- cwd : tgtPath ,
55
- } ) ;
56
- } ,
57
- ) ;
38
+ return new Promise < void > ( ( resolve , reject ) => {
39
+ this . execInstance . exec (
40
+ namespace ,
41
+ podName ,
42
+ containerName ,
43
+ command ,
44
+ writerStream ,
45
+ errStream ,
46
+ null ,
47
+ false ,
48
+ async ( { status } ) => {
49
+ try {
50
+ writerStream . close ( ) ;
51
+ if ( status === 'Failure' || errStream . size ( ) ) {
52
+ throw new Error ( `Error from cpFromPod - details: \n ${ errStream . getContentsAsString ( ) } ` ) ;
53
+ }
54
+ await tar . x ( {
55
+ file : tmpFileName ,
56
+ cwd : tgtPath ,
57
+ } ) ;
58
+ resolve ( ) ;
59
+ } catch ( e ) {
60
+ reject ( e ) ;
61
+ }
62
+ } ,
63
+ ) . catch ( reject ) ;
64
+ } ) ;
58
65
}
59
66
60
67
/**
@@ -78,20 +85,24 @@ export class Cp {
78
85
await tar . c ( { file : tmpFileName , cwd } , [ srcPath ] ) ;
79
86
const readStream = fs . createReadStream ( tmpFileName ) ;
80
87
const errStream = new WritableStreamBuffer ( ) ;
81
- this . execInstance . exec (
82
- namespace ,
83
- podName ,
84
- containerName ,
85
- command ,
86
- null ,
87
- errStream ,
88
- readStream ,
89
- false ,
90
- async ( { status } ) => {
91
- if ( status === 'Failure' || errStream . size ( ) ) {
92
- throw new Error ( `Error from cpToPod - details: \n ${ errStream . getContentsAsString ( ) } ` ) ;
93
- }
94
- } ,
95
- ) ;
88
+ return new Promise < void > ( ( resolve , reject ) => {
89
+ this . execInstance . exec (
90
+ namespace ,
91
+ podName ,
92
+ containerName ,
93
+ command ,
94
+ null ,
95
+ errStream ,
96
+ readStream ,
97
+ false ,
98
+ async ( { status } ) => {
99
+ if ( status === 'Failure' || errStream . size ( ) ) {
100
+ reject ( new Error ( `Error from cpToPod - details: \n ${ errStream . getContentsAsString ( ) } ` ) ) ;
101
+ } else {
102
+ resolve ( ) ;
103
+ }
104
+ } ,
105
+ ) . catch ( reject ) ;
106
+ } ) ;
96
107
}
97
108
}
0 commit comments