Skip to content

Commit 412248c

Browse files
committed
C#: Address review comments
1 parent 9f375de commit 412248c

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

csharp/extractor/Semmle.Extraction.CSharp.Standalone/Runtime.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static IEnumerable<string> CoreRuntimes
2121
{
2222
get
2323
{
24-
var dotnetPath = FileUtils.FindExecutableOnPath("dotnet");
24+
var dotnetPath = FileUtils.FindExecutableOnPath(Win32.IsWindows() ? "dotnet.exe" : "dotnet");
2525
var dotnetDirs = dotnetPath != null
2626
? new[] { dotnetPath }
2727
: new[] { "/usr/share/dotnet", @"C:\Program Files\dotnet" };
@@ -41,7 +41,7 @@ public static IEnumerable<string> DesktopRuntimes
4141
{
4242
get
4343
{
44-
var monoPath = FileUtils.FindExecutableOnPath("mono");
44+
var monoPath = FileUtils.FindExecutableOnPath(Win32.IsWindows() ? "mono.exe" : "mono");
4545
var monoDirs = monoPath != null
4646
? new[] { monoPath }
4747
: new[] { "/usr/lib/mono", @"C:\Program Files\Mono\lib\mono" };

csharp/extractor/Semmle.Util/FileUtils.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,17 @@ public static void TryDelete(string file)
6262
/// </summary>
6363
public static string FindExecutableOnPath(string exe)
6464
{
65-
var isWindows = Win32.IsWindows();
66-
var paths = Environment.GetEnvironmentVariable("PATH").Split(isWindows ? ';' : ':');
67-
var exes = isWindows
68-
? Environment.GetEnvironmentVariable("PATHEXT").Split(';').Select(ext => exe + ext)
69-
: new[] { exe };
65+
var paths = Environment.GetEnvironmentVariable("PATH").Split(Path.PathSeparator);
66+
string[] exes;
67+
if (Win32.IsWindows())
68+
{
69+
var extensions = Environment.GetEnvironmentVariable("PATHEXT").Split(';').ToArray();
70+
exes = extensions.Any(exe.EndsWith) ? new[] { exe } : extensions.Select(ext => exe + ext).ToArray();
71+
}
72+
else
73+
{
74+
exes = new[] { exe };
75+
}
7076
var candidates = paths.Where(path => exes.Any(exe0 => File.Exists(Path.Combine(path, exe0))));
7177
return candidates.FirstOrDefault();
7278
}

0 commit comments

Comments
 (0)