From 7b369174c94538dce70da91ca2011833865971cd Mon Sep 17 00:00:00 2001 From: Harald Nielsen Date: Tue, 19 Sep 2023 11:16:49 +0200 Subject: [PATCH 1/2] On windows there can be problems with Tools that do not support Unicode, and Username containing Unicode chars. https://github.com/dotnet/msbuild/issues/9229 --- src/Shared/TempFileUtilities.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Shared/TempFileUtilities.cs b/src/Shared/TempFileUtilities.cs index c73af5ba444..880f4db9c08 100644 --- a/src/Shared/TempFileUtilities.cs +++ b/src/Shared/TempFileUtilities.cs @@ -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 @@ -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) { From d5418dfb8dc11fca1fd85a66dc34a84d201842e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20Kj=C3=A6r=20Nielsen?= Date: Thu, 21 Sep 2023 07:54:41 +0200 Subject: [PATCH 2/2] Update src/Shared/TempFileUtilities.cs by review cleanup Co-authored-by: Forgind <12969783+Forgind@users.noreply.github.com> --- src/Shared/TempFileUtilities.cs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Shared/TempFileUtilities.cs b/src/Shared/TempFileUtilities.cs index 880f4db9c08..190f0dddf2b 100644 --- a/src/Shared/TempFileUtilities.cs +++ b/src/Shared/TempFileUtilities.cs @@ -38,16 +38,10 @@ 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 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 msbuildTempFolder = NativeMethodsShared.IsWindows ? + msbuildTempFolderPrefix : + msbuildTempFolderPrefix + Environment.UserName; string basePath = Path.Combine(Path.GetTempPath(), msbuildTempFolder);