diff --git a/eng/Versions.props b/eng/Versions.props index 5546a3e0f8d..c20a77c8cad 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -2,12 +2,12 @@ - 17.10.45 + 17.10.46 release 17.8.3 15.1.0.0 servicing - test true diff --git a/src/Shared/TempFileUtilities.cs b/src/Shared/TempFileUtilities.cs index 190f0dddf2b..db69ddd3dad 100644 --- a/src/Shared/TempFileUtilities.cs +++ b/src/Shared/TempFileUtilities.cs @@ -18,7 +18,6 @@ internal static partial class FileUtilities { // For the current user, these correspond to read, write, and execute permissions. // 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"; @@ -38,40 +37,21 @@ 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() { - // 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 path = null; - string basePath = Path.Combine(Path.GetTempPath(), msbuildTempFolder); - - if (NativeMethodsShared.IsLinux && NativeMethodsShared.mkdir(basePath, userRWX) != 0) + if (NativeMethodsShared.IsLinux) { - if (NativeMethodsShared.chmod(basePath, userRWX) == 0) - { - // Current user owns this file; we can read and write to it. It is reasonable here to assume it was created properly by MSBuild and can be used - // for temporary files. - } - else - { - // Another user created a folder pretending to be us! Find a folder we can actually use. - int extraBits = 0; - string pathToCheck = basePath + extraBits; - while (NativeMethodsShared.mkdir(pathToCheck, userRWX) != 0 && NativeMethodsShared.chmod(pathToCheck, userRWX) != 0) - { - extraBits++; - pathToCheck = basePath + extraBits; - } - - basePath = pathToCheck; - } +#if NET // always true, Linux implies NET + path = Directory.CreateTempSubdirectory(msbuildTempFolderPrefix).FullName; +#endif } else { - Directory.CreateDirectory(basePath); + path = Path.Combine(Path.GetTempPath(), msbuildTempFolderPrefix); + Directory.CreateDirectory(path); } - return FileUtilities.EnsureTrailingSlash(basePath); + return FileUtilities.EnsureTrailingSlash(path); } ///