Skip to content

Commit bef8217

Browse files
committed
Special case workaround for macOS temp folder
1 parent 3f9b0f9 commit bef8217

File tree

1 file changed

+16
-28
lines changed

1 file changed

+16
-28
lines changed

LibGit2Sharp.Tests/TestHelpers/Constants.cs

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -55,44 +55,32 @@ public static string BuildPath()
5555
{
5656
string tempPath = null;
5757

58-
if (IsRunningOnUnix)
58+
const string LibGit2TestPath = "LibGit2TestPath";
59+
60+
// We're running on .Net/Windows
61+
if (Environment.GetEnvironmentVariables().Contains(LibGit2TestPath))
5962
{
60-
// We're running on Mono/*nix. Let's unwrap the path
61-
tempPath = UnwrapUnixTempPath();
63+
Trace.TraceInformation("{0} environment variable detected", LibGit2TestPath);
64+
tempPath = Environment.GetEnvironmentVariables()[LibGit2TestPath] as String;
6265
}
63-
else
66+
67+
if (String.IsNullOrWhiteSpace(tempPath) || !Directory.Exists(tempPath))
68+
{
69+
Trace.TraceInformation("Using default test path value");
70+
tempPath = Path.GetTempPath();
71+
}
72+
73+
//workaround macOS symlinking its temp folder
74+
if (tempPath.StartsWith("/var"))
6475
{
65-
const string LibGit2TestPath = "LibGit2TestPath";
66-
67-
// We're running on .Net/Windows
68-
if (Environment.GetEnvironmentVariables().Contains(LibGit2TestPath))
69-
{
70-
Trace.TraceInformation("{0} environment variable detected", LibGit2TestPath);
71-
tempPath = Environment.GetEnvironmentVariables()[LibGit2TestPath] as String;
72-
}
73-
74-
if (String.IsNullOrWhiteSpace(tempPath) || !Directory.Exists(tempPath))
75-
{
76-
Trace.TraceInformation("Using default test path value");
77-
tempPath = Path.GetTempPath();
78-
}
76+
tempPath = "/private" + tempPath;
7977
}
8078

8179
string testWorkingDirectory = Path.Combine(tempPath, "LibGit2Sharp-TestRepos");
8280
Trace.TraceInformation("Test working directory set to '{0}'", testWorkingDirectory);
8381
return testWorkingDirectory;
8482
}
8583

86-
private static string UnwrapUnixTempPath()
87-
{
88-
var type = Type.GetType("Mono.Unix.UnixPath, Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756");
89-
90-
return (string)type.GetMethod("GetCompleteRealPath",
91-
BindingFlags.Static | BindingFlags.FlattenHierarchy |
92-
BindingFlags.InvokeMethod | BindingFlags.Public).Invoke(
93-
null, new object[] { Path.GetTempPath() });
94-
}
95-
9684
// To help with creating secure strings to test with.
9785
internal static SecureString StringToSecureString(string str)
9886
{

0 commit comments

Comments
 (0)