Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the MIT license. See License.txt in the project root for full license information. -->
<Project>
<PropertyGroup>
<VersionPrefix>17.11.47</VersionPrefix>
<VersionPrefix>17.11.48</VersionPrefix>
<DotNetFinalVersionKind>release</DotNetFinalVersionKind>
<PackageValidationBaselineVersion>17.10.4</PackageValidationBaselineVersion>
<AssemblyVersion>15.1.0.0</AssemblyVersion>
Expand Down
36 changes: 8 additions & 28 deletions src/Shared/TempFileUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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);
}

/// <summary>
Expand Down