Skip to content

Commit 09f59f0

Browse files
committed
@tmds feedback
1 parent c783280 commit 09f59f0

File tree

1 file changed

+4
-26
lines changed

1 file changed

+4
-26
lines changed

src/Resolvers/Microsoft.DotNet.NativeWrapper/EnvironmentProvider.cs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -75,34 +75,12 @@ private IEnumerable<string> SearchPaths
7575
{
7676
// e.g. on Linux the 'dotnet' command from PATH is a symlink so we need to
7777
// resolve it to get the actual path to the binary
78-
dotnetExeFromPath = GetRealPath(dotnetExeFromPath);
79-
80-
static string GetRealPath(string path)
78+
FileSystemInfo fileInfo = new FileInfo(dotnetExeFromPath);
79+
if ((fileInfo.Attributes & FileAttributes.ReparsePoint) != 0)
8180
{
82-
FileInfo fileInfo = new(path);
83-
if (fileInfo.LinkTarget != null)
84-
{
85-
var resolved = fileInfo.ResolveLinkTarget(true);
86-
return resolved?.Exists is true ? resolved.FullName : path;
87-
}
88-
89-
string invariantPart = string.Empty;
90-
DirectoryInfo? parentDirectory = fileInfo.Directory;
91-
while (parentDirectory is not null)
92-
{
93-
invariantPart = path[parentDirectory.FullName.Length..];
94-
if (parentDirectory.LinkTarget != null)
95-
{
96-
var resolved = parentDirectory.ResolveLinkTarget(true);
97-
if (resolved?.Exists is true)
98-
return Path.Join(resolved.FullName, invariantPart);
99-
}
100-
101-
parentDirectory = parentDirectory.Parent;
102-
}
103-
104-
return path;
81+
fileInfo = fileInfo.ResolveLinkTarget(returnFinalTarget: true) ?? fileInfo;
10582
}
83+
dotnetExeFromPath = fileInfo.FullName;
10684
}
10785
#endif
10886

0 commit comments

Comments
 (0)