Skip to content

Commit

Permalink
On windows there can be problems with Tools that do not support Unico…
Browse files Browse the repository at this point in the history
…de, and Username containing Unicode chars.

#9229
  • Loading branch information
hknielsen committed Sep 19, 2023
1 parent 1b84c9b commit 7b36917
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Shared/TempFileUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ internal static partial class FileUtilities
// Lower order bits correspond to the same for "group" or "other" users.
private const int userRWX = 0x100 | 0x80 | 0x40;
private static string tempFileDirectory = null;
private const string msbuildTempFolderPrefix = "MSBuildTemp";

internal static string TempFileDirectory
{
get
Expand All @@ -36,7 +38,18 @@ internal static void ClearTempFileDirectory()
// For all native calls, directly check their return values to prevent bad actors from getting in between checking if a directory exists and returning it.
private static string CreateFolderUnderTemp()
{
string basePath = Path.Combine(Path.GetTempPath(), $"MSBuildTemp{Environment.UserName}");
string msbuildTempFolder;
// On windows Username with Unicode chars can give issues, so we dont append username to the temp folder name.
if (NativeMethodsShared.IsWindows)
{
msbuildTempFolder = msbuildTempFolderPrefix;
}
else
{
msbuildTempFolder = msbuildTempFolderPrefix + Environment.UserName;
}

string basePath = Path.Combine(Path.GetTempPath(), msbuildTempFolder);

if (NativeMethodsShared.IsLinux && NativeMethodsShared.mkdir(basePath, userRWX) != 0)
{
Expand Down

0 comments on commit 7b36917

Please sign in to comment.