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
30 changes: 29 additions & 1 deletion src/Compilers/Test/Core/TempFiles/TempRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,35 @@ public sealed class TempRoot : IDisposable

static TempRoot()
{
Root = Path.Combine(Path.GetTempPath(), "RoslynTests");
var tempDirectory = new DirectoryInfo(Path.GetTempPath());

#if NET
// When running on MacOS, `Path.GetTempPath()` will return "/var/folders/..." which is a symlink to "/private/var/folders/...". This
// can cause issues when watching files under the temp directory, as the FileSystemWatcher will report changes using the real path.
// So, we need to adjust this path by walking up the temp path until we find a directory that is a link and resolve it.

if (tempDirectory.LinkTarget != null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unfortunate there's not an API we can just call that does this for us.

{
tempDirectory = (DirectoryInfo)Directory.ResolveLinkTarget(tempDirectory.FullName, returnFinalTarget: true);
}
else
{
var parentDirectory = tempDirectory.Parent;
while (parentDirectory != null && parentDirectory.LinkTarget == null)
{
parentDirectory = parentDirectory.Parent;
}

if (parentDirectory != null)
{
var relativePath = Path.GetRelativePath(parentDirectory.FullName, tempDirectory.FullName);
var realPath = Directory.ResolveLinkTarget(parentDirectory.FullName, returnFinalTarget: true).FullName;
tempDirectory = new DirectoryInfo(Path.GetFullPath(Path.Combine(realPath, relativePath)));
}
}
#endif

Root = Path.Combine(tempDirectory.FullName, "RoslynTests");
Directory.CreateDirectory(Root);
}

Expand Down
Loading
Loading