Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Fixes #585 Use fs.stat instead of fs.exists (#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Nov 2, 2016
1 parent d7cb9cd commit 1687b3c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/goPath.ts
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 = (<string>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;
}
}

0 comments on commit 1687b3c

Please sign in to comment.