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

Commit

Permalink
File exists check by apply code coverage command doesnt need access c…
Browse files Browse the repository at this point in the history
…hecks
  • Loading branch information
ramya-rao-a committed Feb 3, 2020
1 parent 45fb62b commit b6d5c41
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/goPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function getBinPathFromEnvVar(toolName: string, envVarValue: string, appe
const paths = envVarValue.split(path.delimiter);
for (const p of paths) {
const binpath = path.join(p, appendBinToPath ? 'bin' : '', toolName);
if (fileExists(binpath)) {
if (executableFileExists(binpath)) {
return binpath;
}
}
Expand All @@ -35,7 +35,7 @@ export function getBinPathWithPreferredGopath(toolName: string, preferredGopaths
return binPathCache[toolName];
}

if (alternateTool && path.isAbsolute(alternateTool) && fileExists(alternateTool)) {
if (alternateTool && path.isAbsolute(alternateTool) && executableFileExists(alternateTool)) {
binPathCache[toolName] = alternateTool;
return alternateTool;
}
Expand Down Expand Up @@ -75,7 +75,7 @@ export function getBinPathWithPreferredGopath(toolName: string, preferredGopaths
// Check default path for go
if (toolName === 'go') {
const defaultPathForGo = process.platform === 'win32' ? 'C:\\Go\\bin\\go.exe' : '/usr/local/go/bin/go';
if (fileExists(defaultPathForGo)) {
if (executableFileExists(defaultPathForGo)) {
binPathCache[toolName] = defaultPathForGo;
return defaultPathForGo;
}
Expand All @@ -93,7 +93,7 @@ function correctBinname(toolName: string) {
return toolName;
}

export function fileExists(filePath: string): boolean {
function executableFileExists(filePath: string): boolean {
let exists = true;
try {
exists = fs.statSync(filePath).isFile();
Expand All @@ -106,6 +106,14 @@ export function fileExists(filePath: string): boolean {
return exists;
}

export function fileExists(filePath: string): boolean {
try {
return fs.statSync(filePath).isFile();
} catch (e) {
return false;
}
}

export function clearCacheForTools() {
binPathCache = {};
}
Expand Down

0 comments on commit b6d5c41

Please sign in to comment.