From 018a38272959f391d36ebb7bf77827465d2caffe Mon Sep 17 00:00:00 2001 From: shayne Date: Tue, 25 Apr 2023 13:07:17 -0400 Subject: [PATCH] cmd/tailscale/cli: [serve] fix MinGW path conversion (#7964) Fixes #7963 Signed-off-by: Shayne Sweeney --- cmd/tailscale/cli/serve.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cmd/tailscale/cli/serve.go b/cmd/tailscale/cli/serve.go index 7691c7497..59518fecc 100644 --- a/cmd/tailscale/cli/serve.go +++ b/cmd/tailscale/cli/serve.go @@ -16,6 +16,7 @@ "path" "path/filepath" "reflect" + "runtime" "sort" "strconv" "strings" @@ -412,6 +413,7 @@ func cleanMountPoint(mount string) (string, error) { if mount == "" { return "", errors.New("mount point cannot be empty") } + mount = cleanMinGWPathConversionIfNeeded(mount) if !strings.HasPrefix(mount, "/") { mount = "/" + mount } @@ -422,6 +424,26 @@ func cleanMountPoint(mount string) (string, error) { return "", fmt.Errorf("invalid mount point %q", mount) } +// cleanMinGWPathConversionIfNeeded strips the EXEPATH prefix from the given +// path if the path is a MinGW(ish) (Windows) shell arg. +// +// MinGW(ish) (Windows) shells perform POSIX-to-Windows path conversion +// converting the leading "/" of any shell arg to the EXEPATH, which mangles the +// mount point. Strip the EXEPATH prefix if it exists. #7963 +// +// "/C:/Program Files/Git/foo" -> "/foo" +func cleanMinGWPathConversionIfNeeded(path string) string { + // Only do this on Windows. + if runtime.GOOS != "windows" { + return path + } + if _, ok := os.LookupEnv("MSYSTEM"); ok { + exepath := filepath.ToSlash(os.Getenv("EXEPATH")) + path = strings.TrimPrefix(path, exepath) + } + return path +} + func expandProxyTarget(source string) (string, error) { if !strings.Contains(source, "://") { source = "http://" + source