Skip to content

Commit 114da37

Browse files
committed
Switch from existsSync to accessSync.
1 parent c9d4328 commit 114da37

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/config.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,29 @@ export class KubeConfig {
1717
// Only public for testing.
1818
public static findHomeDir(): string | null {
1919
if (process.env.HOME) {
20-
if (fs.existsSync(process.env.HOME)) {
20+
try {
21+
fs.accessSync(process.env.HOME);
2122
return process.env.HOME;
22-
}
23+
// tslint:disable-next-line:no-empty
24+
} catch (ignore) {}
2325
}
2426
if (process.platform !== 'win32') {
2527
return null;
2628
}
2729
if (process.env.HOMEDRIVE && process.env.HOMEPATH) {
2830
const dir = path.join(process.env.HOMEDRIVE, process.env.HOMEPATH);
29-
if (fs.existsSync(dir)) {
31+
try {
32+
fs.accessSync(dir);
3033
return dir;
31-
}
34+
// tslint:disable-next-line:no-empty
35+
} catch (ignore) {}
3236
}
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) {}
3543
}
3644
return null;
3745
}
@@ -228,10 +236,12 @@ export class KubeConfig {
228236
const home = KubeConfig.findHomeDir();
229237
if (home) {
230238
const config = path.join(home, '.kube', 'config');
231-
if (fs.existsSync(config)) {
239+
try {
240+
fs.accessSync(config);
232241
this.loadFromFile(config);
233242
return;
234-
}
243+
// tslint:disable-next-line:no-empty
244+
} catch (ignore) {}
235245
}
236246
if (process.platform === 'win32' && shelljs.which('wsl.exe')) {
237247
// TODO: Handle if someome set $KUBECONFIG in wsl here...
@@ -242,10 +252,12 @@ export class KubeConfig {
242252
}
243253
}
244254

245-
if (fs.existsSync(Config.SERVICEACCOUNT_TOKEN_PATH)) {
255+
try {
256+
fs.accessSync(Config.SERVICEACCOUNT_TOKEN_PATH);
246257
this.loadFromCluster();
247258
return;
248-
}
259+
// tslint:disable-next-line:no-empty
260+
} catch (ignore) {}
249261

250262
this.loadFromClusterAndUser(
251263
{name: 'cluster', server: 'http://localhost:8080'} as Cluster,

0 commit comments

Comments
 (0)