Skip to content
Merged
Changes from all commits
Commits
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
14 changes: 12 additions & 2 deletions src/Models/IpcChannel.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down