Skip to content

Commit

Permalink
Exception handling in DotNetCliGenerator.GetRootDirectory, fix #2436
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyAkinshin committed Oct 16, 2023
1 parent d17c6ad commit af9c5c6
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,25 @@ internal static bool GetProjectRootDirectory(out DirectoryInfo directoryInfo)
return GetRootDirectory(IsRootProjectFolder, out directoryInfo);
}

internal static bool GetRootDirectory(Func<DirectoryInfo, bool> condition, out DirectoryInfo directoryInfo)
internal static bool GetRootDirectory(Func<DirectoryInfo, bool> condition, out DirectoryInfo? directoryInfo)
{
directoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory());
while (directoryInfo != null)
directoryInfo = null;
try
{
if (condition(directoryInfo))
directoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory());
while (directoryInfo != null)
{
return true;
}
if (condition(directoryInfo))
{
return true;
}

directoryInfo = directoryInfo.Parent;
directoryInfo = directoryInfo.Parent;
}
}
catch
{
return false;
}

return false;
Expand Down

0 comments on commit af9c5c6

Please sign in to comment.