11using System ;
22using System . IO ;
33using System . IO . Pipes ;
4+ using System . Security . Cryptography ;
5+ using System . Text ;
46using System . Threading ;
57using System . Threading . Tasks ;
68
@@ -19,7 +21,7 @@ public IpcChannel()
1921 _singletonLock = File . Open ( Path . Combine ( Native . OS . DataDir , "process.lock" ) , FileMode . OpenOrCreate , FileAccess . ReadWrite , FileShare . None ) ;
2022 IsFirstInstance = true ;
2123 _server = new NamedPipeServerStream (
22- "SourceGitIPCChannel" + Environment . UserName ,
24+ GetPipeName ( ) ,
2325 PipeDirection . In ,
2426 - 1 ,
2527 PipeTransmissionMode . Byte ,
@@ -37,7 +39,7 @@ public void SendToFirstInstance(string cmd)
3739 {
3840 try
3941 {
40- using ( var client = new NamedPipeClientStream ( "." , "SourceGitIPCChannel" + Environment . UserName , PipeDirection . Out , PipeOptions . Asynchronous | PipeOptions . CurrentUserOnly ) )
42+ using ( var client = new NamedPipeClientStream ( "." , GetPipeName ( ) , PipeDirection . Out , PipeOptions . Asynchronous | PipeOptions . CurrentUserOnly ) )
4143 {
4244 client . Connect ( 1000 ) ;
4345 if ( ! client . IsConnected )
@@ -67,6 +69,14 @@ public void Dispose()
6769 _singletonLock ? . Dispose ( ) ;
6870 }
6971
72+ private static string GetPipeName ( )
73+ {
74+ 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 } ";
78+ }
79+
7080 private async void StartServer ( )
7181 {
7282 using var reader = new StreamReader ( _server ) ;
0 commit comments