Skip to content

Commit

Permalink
Merge pull request dotnet#9232 from hknielsen/dont-append-username
Browse files Browse the repository at this point in the history
On windows there can be problems with Tools that do not support Unicode
  • Loading branch information
JanKrivanek authored Oct 5, 2023
2 parents 9f27e8f + fe1f4fa commit f2f7fcf
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 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,12 @@ 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}");
// On windows Username with Unicode chars can give issues, so we dont append username to the temp folder name.
string msbuildTempFolder = NativeMethodsShared.IsWindows ?
msbuildTempFolderPrefix :
msbuildTempFolderPrefix + Environment.UserName;

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

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

0 comments on commit f2f7fcf

Please sign in to comment.