Skip to content

Commit c962f55

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

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
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(Win32.IsWindows() ? "dotnet.exe" : "dotnet");
24+
var dotnetPath = FileUtils.FindProgramOnPath(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(Win32.IsWindows() ? "mono.exe" : "mono");
44+
var monoPath = FileUtils.FindProgramOnPath(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: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,29 @@ public static void TryDelete(string file)
5454
}
5555

5656
/// <summary>
57-
/// Finds the path for the executable <paramref name="exe"/> based on the
57+
/// Finds the path for the program <paramref name="prog"/> based on the
5858
/// <code>PATH</code> environment variable, and in the case of Windows the
5959
/// <code>PATHEXT</code> environment variable.
6060
///
6161
/// Returns <code>null</code> of no path can be found.
6262
/// </summary>
63-
public static string FindExecutableOnPath(string exe)
63+
public static string FindProgramOnPath(string prog)
6464
{
65-
var paths = Environment.GetEnvironmentVariable("PATH").Split(Path.PathSeparator);
65+
var paths = Environment.GetEnvironmentVariable("PATH")?.Split(Path.PathSeparator);
6666
string[] exes;
6767
if (Win32.IsWindows())
6868
{
69-
var extensions = Environment.GetEnvironmentVariable("PATHEXT").Split(';').ToArray();
70-
exes = extensions.Any(exe.EndsWith) ? new[] { exe } : extensions.Select(ext => exe + ext).ToArray();
69+
var extensions = Environment.GetEnvironmentVariable("PATHEXT")?.Split(';')?.ToArray();
70+
exes = extensions == null || extensions.Any(prog.EndsWith)
71+
? new[] { prog }
72+
: extensions.Select(ext => prog + ext).ToArray();
7173
}
7274
else
7375
{
74-
exes = new[] { exe };
76+
exes = new[] { prog };
7577
}
76-
var candidates = paths.Where(path => exes.Any(exe0 => File.Exists(Path.Combine(path, exe0))));
77-
return candidates.FirstOrDefault();
78+
var candidates = paths?.Where(path => exes.Any(exe0 => File.Exists(Path.Combine(path, exe0))));
79+
return candidates?.FirstOrDefault();
7880
}
7981
}
8082
}

0 commit comments

Comments
 (0)