From a05e5948b6ddf1ccb4f2c36a17ec6fb6119c29c6 Mon Sep 17 00:00:00 2001 From: Russ Magee Date: Mon, 8 Dec 2025 22:44:54 -0800 Subject: [PATCH] Fixes for xc to work in MSYS2/MINGW --- auth.go | 27 ++++++++++++++++++++++++--- xs/xs.go | 16 ++++++++++++++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/auth.go b/auth.go index f10ecf8..f5bb1f0 100644 --- a/auth.go +++ b/auth.go @@ -215,18 +215,39 @@ func AuthUserByToken(ctx *AuthCtx, username string, connhostname string, auth st return } +func GroomFsPath(path string) (ret string) { + pathRoot := os.Getenv("MINGW_ROOT") + if pathRoot != "" { + ret = path[len(pathRoot):] + ret = strings.ReplaceAll(ret, "\\", "/") + } else { + ret = path + } + //fmt.Printf("groomed fspath:%v\n", ret) + return +} + func GetTool(tool string) (ret string) { - ret = "/bin/" + tool + cmdSuffix := "" + pathRoot := os.Getenv("MINGW_ROOT") + + if pathRoot != "" { + cmdSuffix = ".exe" + } + + //fmt.Printf("pathRoot:%v cmdSuffix:%v\n", pathRoot, cmdSuffix) + + ret = pathRoot + "/bin/" + tool + cmdSuffix _, err := os.Stat(ret) if err == nil { return ret } - ret = "/usr/bin/" + tool + ret = pathRoot + "/usr/bin/" + tool + cmdSuffix _, err = os.Stat(ret) if err == nil { return ret } - ret = "/usr/local/bin/" + tool + ret = pathRoot + "/usr/local/bin/" + tool + cmdSuffix _, err = os.Stat(ret) if err == nil { return ret diff --git a/xs/xs.go b/xs/xs.go index 9b5a658..788c456 100755 --- a/xs/xs.go +++ b/xs/xs.go @@ -294,7 +294,14 @@ func buildCmdLocalToRemote(copyQuiet bool, copyLimitBPS uint, files string) (cap captureStderr = true cmd = xs.GetTool("tar") - args = []string{"-cz", "-f", "/dev/stdout"} + //fmt.Printf("GetTool found cmd:%v\n", cmd) + /* Explicit -f /dev/stdout doesn't work in MINGW/MSYS64 + * as '/dev/stdout' doesn't actually appear in the /dev/ filesystem...? + * And it appears not to actually be required as without -f stdout is + * implied. -rlm 2025-12-07 + */ + //args = []string{"-cz", "-f", "/dev/stdout"} + args = []string{"-cz"} files = strings.TrimSpace(files) // Awesome fact: tar actually can take multiple -C args, and // changes to the dest dir *as it sees each one*. This enables @@ -310,6 +317,7 @@ func buildCmdLocalToRemote(copyQuiet bool, copyLimitBPS uint, files string) (cap // remote destDir. for _, v := range strings.Split(files, " ") { v, _ = filepath.Abs(v) // #nosec + v = xs.GroomFsPath(v) dirTmp, fileTmp := path.Split(v) if dirTmp == "" { args = append(args, fileTmp) @@ -322,7 +330,8 @@ func buildCmdLocalToRemote(copyQuiet bool, copyLimitBPS uint, files string) (cap bandwidthInBytesPerSec := " -L " + fmt.Sprintf("%d", copyLimitBPS) displayOpts := " -pre " //nolint:goconst,nolintlint cmd = xs.GetTool("bash") - args = []string{"-c", xs.GetTool("tar") + " -cz -f /dev/stdout "} + //args = []string{"-c", xs.GetTool("tar") + " -cz -f /dev/stdout "} + args = []string{"-c", xs.GetTool("tar") + " -cz "} files = strings.TrimSpace(files) // Awesome fact: tar actually can take multiple -C args, and // changes to the dest dir *as it sees each one*. This enables @@ -338,6 +347,7 @@ func buildCmdLocalToRemote(copyQuiet bool, copyLimitBPS uint, files string) (cap // remote destDir. for _, v := range strings.Split(files, " ") { v, _ = filepath.Abs(v) // #nosec + v = xs.GroomFsPath(v) dirTmp, fileTmp := path.Split(v) if dirTmp == "" { args[1] = args[1] + fileTmp + " " @@ -386,6 +396,8 @@ func doCopyMode(conn *xsnet.Conn, remoteDest bool, files string, copyQuiet bool, c.Stderr = os.Stderr } + //fmt.Printf("cmd:%v args:%v\n", cmdName, cmdArgs) + // Start the command (no pty) err = c.Start() // returns immediately /////////////