@@ -17,21 +17,29 @@ export class KubeConfig {
17
17
// Only public for testing.
18
18
public static findHomeDir ( ) : string | null {
19
19
if ( process . env . HOME ) {
20
- if ( fs . existsSync ( process . env . HOME ) ) {
20
+ try {
21
+ fs . accessSync ( process . env . HOME ) ;
21
22
return process . env . HOME ;
22
- }
23
+ // tslint:disable-next-line:no-empty
24
+ } catch ( ignore ) { }
23
25
}
24
26
if ( process . platform !== 'win32' ) {
25
27
return null ;
26
28
}
27
29
if ( process . env . HOMEDRIVE && process . env . HOMEPATH ) {
28
30
const dir = path . join ( process . env . HOMEDRIVE , process . env . HOMEPATH ) ;
29
- if ( fs . existsSync ( dir ) ) {
31
+ try {
32
+ fs . accessSync ( dir ) ;
30
33
return dir ;
31
- }
34
+ // tslint:disable-next-line:no-empty
35
+ } catch ( ignore ) { }
32
36
}
33
- if ( process . env . USERPROFILE && fs . existsSync ( process . env . USERPROFILE ) ) {
34
- return process . env . USERPROFILE ;
37
+ if ( process . env . USERPROFILE ) {
38
+ try {
39
+ fs . accessSync ( process . env . USERPROFILE ) ;
40
+ return process . env . USERPROFILE ;
41
+ // tslint:disable-next-line:no-empty
42
+ } catch ( ignore ) { }
35
43
}
36
44
return null ;
37
45
}
@@ -228,10 +236,12 @@ export class KubeConfig {
228
236
const home = KubeConfig . findHomeDir ( ) ;
229
237
if ( home ) {
230
238
const config = path . join ( home , '.kube' , 'config' ) ;
231
- if ( fs . existsSync ( config ) ) {
239
+ try {
240
+ fs . accessSync ( config ) ;
232
241
this . loadFromFile ( config ) ;
233
242
return ;
234
- }
243
+ // tslint:disable-next-line:no-empty
244
+ } catch ( ignore ) { }
235
245
}
236
246
if ( process . platform === 'win32' && shelljs . which ( 'wsl.exe' ) ) {
237
247
// TODO: Handle if someome set $KUBECONFIG in wsl here...
@@ -242,10 +252,12 @@ export class KubeConfig {
242
252
}
243
253
}
244
254
245
- if ( fs . existsSync ( Config . SERVICEACCOUNT_TOKEN_PATH ) ) {
255
+ try {
256
+ fs . accessSync ( Config . SERVICEACCOUNT_TOKEN_PATH ) ;
246
257
this . loadFromCluster ( ) ;
247
258
return ;
248
- }
259
+ // tslint:disable-next-line:no-empty
260
+ } catch ( ignore ) { }
249
261
250
262
this . loadFromClusterAndUser (
251
263
{ name : 'cluster' , server : 'http://localhost:8080' } as Cluster ,
0 commit comments