Skip to content

Commit cb2dfbb

Browse files
committed
Improve artifacts path computation
1 parent 46bd143 commit cb2dfbb

File tree

1 file changed

+5
-22
lines changed

1 file changed

+5
-22
lines changed

src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Collections.Immutable;
77
using System.Diagnostics;
88
using System.Security;
9-
using System.Security.Cryptography;
109
using System.Text.RegularExpressions;
1110
using System.Xml;
1211
using Microsoft.Build.Construction;
@@ -201,28 +200,12 @@ ProjectRootElement CreateProjectRootElement(ProjectCollection projectCollection)
201200

202201
static string GetArtifactsPath(string entryPointFilePath)
203202
{
204-
return Path.Join(Path.GetTempPath(), "dotnet", "runfile", Hash(entryPointFilePath));
203+
// We want a location where permissions are expected to be restricted to the current user.
204+
var directory = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
205+
? Path.GetTempPath()
206+
: Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
207+
return Path.Join(directory, "dotnet", "runfile", Sha256Hasher.HashWithNormalizedCasing(entryPointFilePath));
205208
}
206-
207-
static string Hash(string s)
208-
{
209-
Span<byte> hashBytes = stackalloc byte[SHA256.HashSizeInBytes];
210-
int written = SHA256.HashData(Encoding.UTF8.GetBytes(s), hashBytes);
211-
Debug.Assert(written == hashBytes.Length);
212-
return string.Create(hashBytes.Length * 2, hashBytes, static (destination, hashBytes) => ToHex(hashBytes, destination));
213-
}
214-
215-
static void ToHex(ReadOnlySpan<byte> source, Span<char> destination)
216-
{
217-
int i = 0;
218-
foreach (var b in source)
219-
{
220-
destination[i++] = HexChar(b >> 4);
221-
destination[i++] = HexChar(b & 0xF);
222-
}
223-
}
224-
225-
static char HexChar(int x) => (char)((x <= 9) ? (x + '0') : (x + ('a' - 10)));
226209
}
227210

228211
public static void WriteProjectFile(TextWriter writer, ImmutableArray<CSharpDirective> directives)

0 commit comments

Comments
 (0)