Skip to content

Commit a036d65

Browse files
committed
fix: crash due to name of pipeline too long (#2576)
Signed-off-by: leo <longshuang@msn.cn>
1 parent 02598ff commit a036d65

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎src/Models/IpcChannel.cs‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,15 @@ public void Dispose()
7171

7272
private static string GetPipeName()
7373
{
74+
// SourceGit does not support multiple instances on macOS, so we can use a fixed pipe name for macOS.
75+
if (OperatingSystem.IsMacOS())
76+
return "SourceGit";
77+
78+
// Windows and Linux can have multiple instances of SourceGit running (portable-mode), so we need to generate a unique pipe name based on the data directory.
7479
var dataDir = Native.OS.DataDir.Replace('\\', '/').TrimEnd('/');
75-
var hash = SHA256.HashData(Encoding.UTF8.GetBytes(dataDir));
76-
var hashStr = Convert.ToHexString(hash)[..16];
77-
return $"SourceGitIPCChannel{Environment.UserName}_{hashStr}";
80+
var hashStr = $"{Environment.UserName}_{dataDir}";
81+
var hash = Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(hashStr))).Substring(0, 10);
82+
return $"SG_{hash}";
7883
}
7984

8085
private async void StartServer()

0 commit comments

Comments
 (0)