fix(control): normalize executable path case on Windows for PipeName
This commit is contained in:
1 parent
4a565edf11
commit
28d66b408b
2 files changed
+26
No files matched your search
@@ -7,6 +7,8 @@ import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const MaxFrameBytes = 8 << 20
|
||||
@@ -31,7 +33,14 @@ func PipeName() string {
|
||||
if err != nil {
|
||||
exe = "reims-go"
|
||||
}
|
||||
return pipeNameForExecutable(exe)
|
||||
}
|
||||
|
||||
func pipeNameForExecutable(exe string) string {
|
||||
identity := filepath.Clean(exe)
|
||||
if runtime.GOOS == "windows" {
|
||||
identity = strings.ToLower(identity)
|
||||
}
|
||||
sum := sha256.Sum256([]byte(identity))
|
||||
userScope := currentUserScope()
|
||||
return `\\.\pipe\reims-go-control-` + hex.EncodeToString(sum[:8]) + "-" + userScope
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package control
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPipeNameWindowsCaseInsensitive(t *testing.T) {
|
||||
if runtime.GOOS != "windows" {
|
||||
t.Skip("windows-only path normalization test")
|
||||
}
|
||||
upper := pipeNameForExecutable(`D:\Build\reims-go\build\bin\reims-go.exe`)
|
||||
lower := pipeNameForExecutable(`d:\build\reims-go\build\bin\reims-go.exe`)
|
||||
if upper != lower {
|
||||
t.Fatalf("expected case-insensitive pipe name on Windows: %q != %q", upper, lower)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user