Skip to content

Commit 1043026

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

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

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

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -201,28 +201,12 @@ ProjectRootElement CreateProjectRootElement(ProjectCollection projectCollection)
201201

202202
static string GetArtifactsPath(string entryPointFilePath)
203203
{
204-
return Path.Join(Path.GetTempPath(), "dotnet", "runfile", Hash(entryPointFilePath));
204+
// We want a location where permissions are expected to be restricted to the current user.
205+
var directory = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
206+
? Path.GetTempPath()
207+
: Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
208+
return Path.Join(directory, "dotnet", "runfile", Sha256Hasher.HashWithNormalizedCasing(entryPointFilePath));
205209
}
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)));
226210
}
227211

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

0 commit comments

Comments
 (0)