Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Use XxHash128
  • Loading branch information
jjonescz committed Aug 22, 2025
commit b27f7f60847a98e3df7748f0cd97897fc63a84d0
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ public static string GetHostServerPath(bool createDirectory)
// Most Unix systems have a maximum path length limit for Unix Domain Sockets, with Mac having a particularly short one.
// Mac also has a generated temp directory that can be quite long, leaving very little room for the actual pipe name.
// Fortunately, '/tmp' is mandated by POSIX to always be a valid temp directory, so we can use that instead.
const string dotnetServer = "dotnet-server";
const string dotnet = "dotnet";
string baseDirectory = OperatingSystem.IsWindows()
? Path.Join(dotnetServer, Environment.UserName) // it's not a real path on Windows, just a name
: Path.Join("/tmp/", dotnetServer, Environment.UserName);
? Path.Join(dotnet, Environment.UserName) // it's not a real path on Windows, just a name
: Path.Join("/tmp/", dotnet, Environment.UserName);

string sdkPathHashed = Sha256Hasher.HashWithNormalizedCasing(AppContext.BaseDirectory);
string sdkPathHashed = XxHash128Hasher.HashWithNormalizedCasing(AppContext.BaseDirectory);

hostServerPath = Path.Join(baseDirectory, Product.TargetFrameworkVersion, sdkPathHashed);

Expand Down
15 changes: 15 additions & 0 deletions src/Cli/Microsoft.DotNet.Cli.Utils/Sha256Hasher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#if NET

using System.Diagnostics;
using System.IO.Hashing;
using System.Security.Cryptography;

namespace Microsoft.DotNet.Cli.Utils;
Expand All @@ -29,4 +31,17 @@ public static string HashWithNormalizedCasing(string text)
}
}

public static class XxHash128Hasher
{
public static string HashWithNormalizedCasing(string text)
{
text = text.ToUpperInvariant();
var bytes = Encoding.UTF8.GetBytes(text);
Span<byte> hash = stackalloc byte[sizeof(ulong) * 2];
int bytesWritten = XxHash128.Hash(bytes.AsSpan(), hash);
Debug.Assert(bytesWritten == hash.Length);
return Convert.ToHexStringLower(hash);
}
}

#endif