Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion src/Xamarin.Android.Tools.AndroidSdk/ProcessUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,15 @@ internal static IEnumerable<string> FindExecutablesInPath (string executable)

internal static IEnumerable<string> FindExecutablesInDirectory (string dir, string executable)
{
if (!Directory.Exists (dir))
yield break;
foreach (var exe in ExecutableFiles (executable)) {
var exePath = Path.Combine (dir, exe);
string exePath;
try {
exePath = Path.Combine (dir, exe);
} catch (ArgumentException) {
continue;
}
if (File.Exists (exePath))
yield return exePath;
}
Expand Down
11 changes: 8 additions & 3 deletions src/Xamarin.Android.Tools.AndroidSdk/Sdks/AndroidSdkBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,14 @@ static string GetExecutablePath (string? dir, string exe)
if (string.IsNullOrEmpty (dir))
return exe;

foreach (var e in ProcessUtils.ExecutableFiles (exe))
if (File.Exists (Path.Combine (dir, e)))
return e;
foreach (var e in ProcessUtils.ExecutableFiles (exe)) {
try {
if (File.Exists (Path.Combine (dir, e)))
return e;
} catch (ArgumentException) {
continue;
}
}
return exe;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,50 @@ public void Ndk_PathInSdk()
}
}

[Test]
public void Ndk_Path_InvalidChars ()
{
CreateSdks (out string root, out string jdk, out string ndk, out string sdk);

Action<TraceLevel, string> logger = (level, message) => {
Console.WriteLine ($"[{level}] {message}");
if (level == TraceLevel.Error)
Assert.Fail (message);
};

var oldPath = Environment.GetEnvironmentVariable ("PATH");
try {
Environment.SetEnvironmentVariable ("PATH", "\"C:\\IHAVEQUOTES\\\"");
// Check that this doesn't throw
new AndroidSdkInfo (logger, androidSdkPath: sdk, androidNdkPath: null, javaSdkPath: jdk);
} finally {
Environment.SetEnvironmentVariable ("PATH", oldPath);
Directory.Delete (root, recursive: true);
}
}

[Test]
public void Ndk_PathExt_InvalidChars ()
{
CreateSdks (out string root, out string jdk, out string ndk, out string sdk);

Action<TraceLevel, string> logger = (level, message) => {
Console.WriteLine ($"[{level}] {message}");
if (level == TraceLevel.Error)
Assert.Fail (message);
};

var oldPathExt = Environment.GetEnvironmentVariable ("PATHEXT");
try {
Environment.SetEnvironmentVariable ("PATHEXT", string.Join (Path.PathSeparator.ToString (), "\"", ".EXE", ".BAT"));
// Check that this doesn't throw
new AndroidSdkInfo (logger, androidSdkPath: sdk, androidNdkPath: null, javaSdkPath: jdk);
} finally {
Environment.SetEnvironmentVariable ("PATHEXT", oldPathExt);
Directory.Delete (root, recursive: true);
}
}

[Test]
public void Ndk_AndroidSdkDoesNotExist ()
{
Expand Down