|
6 | 6 | using System.Collections.Immutable;
|
7 | 7 | using System.Diagnostics;
|
8 | 8 | using System.Security;
|
9 |
| -using System.Security.Cryptography; |
10 | 9 | using System.Text.RegularExpressions;
|
11 | 10 | using System.Xml;
|
12 | 11 | using Microsoft.Build.Construction;
|
@@ -201,28 +200,12 @@ ProjectRootElement CreateProjectRootElement(ProjectCollection projectCollection)
|
201 | 200 |
|
202 | 201 | static string GetArtifactsPath(string entryPointFilePath)
|
203 | 202 | {
|
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)); |
205 | 208 | }
|
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))); |
226 | 209 | }
|
227 | 210 |
|
228 | 211 | public static void WriteProjectFile(TextWriter writer, ImmutableArray<CSharpDirective> directives)
|
|
0 commit comments