Skip to content

Commit b5f7f28

Browse files
committed
macos environment: add option to ignore paths
Add ability to ignore specified paths when searching the PATH for an executable.
1 parent dc68962 commit b5f7f28

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/shared/Core/EnvironmentBase.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ public virtual Process CreateProcess(string path, string args, bool useShellExec
104104
return new Process { StartInfo = psi };
105105
}
106106

107-
public bool TryLocateExecutable(string program, out string path)
107+
public virtual bool TryLocateExecutable(string program, out string path)
108+
{
109+
return TryLocateExecutable(program, null, out path);
110+
}
111+
112+
internal virtual bool TryLocateExecutable(string program, ICollection<string> pathsToIgnore, out string path)
108113
{
109114
// On UNIX-like systems we would normally use the "which" utility to locate a program,
110115
// but since distributions don't always place "which" in a consistent location we cannot
@@ -124,7 +129,8 @@ public bool TryLocateExecutable(string program, out string path)
124129
foreach (var basePath in paths)
125130
{
126131
string candidatePath = Path.Combine(basePath, program);
127-
if (FileSystem.FileExists(candidatePath))
132+
if (FileSystem.FileExists(candidatePath) && (pathsToIgnore is null ||
133+
!pathsToIgnore.Contains(candidatePath, StringComparer.OrdinalIgnoreCase)))
128134
{
129135
path = candidatePath;
130136
return true;

0 commit comments

Comments
 (0)