From 220e4ddf5d26b1220799fd9ff6aff9d32e1e5b7d Mon Sep 17 00:00:00 2001 From: Ramya Achutha Rao Date: Tue, 1 Nov 2016 14:39:39 -0700 Subject: [PATCH] Fixes #585 Use fs.stat instead of fs.exists --- src/goPath.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/goPath.ts b/src/goPath.ts index f4be592f4..2c0723701 100644 --- a/src/goPath.ts +++ b/src/goPath.ts @@ -21,7 +21,7 @@ export function getBinPathFromEnvVar(toolName: string, envVar: string, appendBin let paths = process.env[envVar].split(path.delimiter); for (let i = 0; i < paths.length; i++) { let binpath = path.join(paths[i], appendBinToPath ? 'bin' : '', toolName); - if (fs.existsSync(binpath)) { + if (fileExists(binpath)) { binPathCache[toolName] = binpath; return binpath; } @@ -69,11 +69,20 @@ function correctBinname(binname: string) { */ export function getGoRuntimePath(): string { if (runtimePathCache !== 'go') return runtimePathCache; + let correctBinNameGo = correctBinname('go'); if (process.env['GOROOT']) { - runtimePathCache = path.join(process.env['GOROOT'], 'bin', correctBinname('go')); + runtimePathCache = path.join(process.env['GOROOT'], 'bin', correctBinNameGo); } else if (process.env['PATH']) { let pathparts = (process.env.PATH).split(path.delimiter); - runtimePathCache = pathparts.map(dir => path.join(dir, correctBinname('go'))).filter(candidate => fs.existsSync(candidate))[0]; + runtimePathCache = pathparts.map(dir => path.join(dir, correctBinNameGo)).filter(candidate => fileExists(candidate))[0]; } return runtimePathCache; } + +function fileExists(filePath: string): boolean { + try { + return fs.statSync(filePath).isFile(); + } catch (e) { + return false; + } +} \ No newline at end of file