From a3d53ec9fed352967feebfefebe4f762700d3d72 Mon Sep 17 00:00:00 2001 From: JC-Chung <52159296+JC-Chung@users.noreply.github.com> Date: Tue, 21 Jul 2026 09:54:05 +0800 Subject: [PATCH] fix: use DataDir hash in IPC pipe name to isolate instances with different data dirs --- src/Models/IpcChannel.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Models/IpcChannel.cs b/src/Models/IpcChannel.cs index 702f0630b..4e9fc0b16 100644 --- a/src/Models/IpcChannel.cs +++ b/src/Models/IpcChannel.cs @@ -1,6 +1,8 @@ using System; using System.IO; using System.IO.Pipes; +using System.Security.Cryptography; +using System.Text; using System.Threading; using System.Threading.Tasks; @@ -19,7 +21,7 @@ public IpcChannel() _singletonLock = File.Open(Path.Combine(Native.OS.DataDir, "process.lock"), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); IsFirstInstance = true; _server = new NamedPipeServerStream( - "SourceGitIPCChannel" + Environment.UserName, + GetPipeName(), PipeDirection.In, -1, PipeTransmissionMode.Byte, @@ -37,7 +39,7 @@ public void SendToFirstInstance(string cmd) { try { - using (var client = new NamedPipeClientStream(".", "SourceGitIPCChannel" + Environment.UserName, PipeDirection.Out, PipeOptions.Asynchronous | PipeOptions.CurrentUserOnly)) + using (var client = new NamedPipeClientStream(".", GetPipeName(), PipeDirection.Out, PipeOptions.Asynchronous | PipeOptions.CurrentUserOnly)) { client.Connect(1000); if (!client.IsConnected) @@ -67,6 +69,14 @@ public void Dispose() _singletonLock?.Dispose(); } + private static string GetPipeName() + { + var dataDir = Native.OS.DataDir.Replace('\\', '/').TrimEnd('/'); + var hash = SHA256.HashData(Encoding.UTF8.GetBytes(dataDir)); + var hashStr = Convert.ToHexString(hash)[..16]; + return $"SourceGitIPCChannel{Environment.UserName}_{hashStr}"; + } + private async void StartServer() { using var reader = new StreamReader(_server);