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

Fixes #585 Use fs.stat instead of fs.exists #595

Merged
merged 1 commit into from
Nov 2, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/goPath.ts
Original file line number Diff line number Diff line change
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;
}
}