Skip to content

Commit cc0b29b

Browse files
committed
pkg/ioutilx: Add WindowsMixedPathFromWindowsSubsystemPath()
WindowsMixedPathFromWindowsSubsystemPath converts a Windows Subsystem path to a Windows mixed path. mixed means using forward slashes instead of backslashes. e.g. /mnt/c/Users/foo/bar -> C:/Users/foo/bar . Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
1 parent 92b8bc3 commit cc0b29b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pkg/ioutilx/ioutilx.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,15 @@ func WindowsSubsystemPathForLinux(ctx context.Context, orig, distro string) (str
6767
}
6868
return strings.TrimSpace(string(out)), nil
6969
}
70+
71+
// WindowsMixedPathFromWindowsSubsystemPath converts a Windows Subsystem path to a Windows mixed path.
72+
// mixed means using forward slashes instead of backslashes.
73+
// e.g. /mnt/c/Users/foo/bar -> C:/Users/foo/bar .
74+
func WindowsMixedPathFromWindowsSubsystemPath(ctx context.Context, orig string) (string, error) {
75+
out, err := exec.CommandContext(ctx, "cygpath", "-m", orig).CombinedOutput()
76+
if err != nil {
77+
logrus.WithError(err).Errorf("failed to convert path from mingw, maybe not using Git ssh?")
78+
return "", err
79+
}
80+
return strings.TrimSpace(string(out)), nil
81+
}

pkg/sshutil/sshutil.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,14 @@ func ExecuteScriptViaInProcessClient(host string, port int, c *sshocker.SSHConfi
579579
if identityFile == "" {
580580
return "", "", errors.New("failed to find IdentityFile in SSHConfig.AdditionalArgs")
581581
}
582+
// Convert path from Windows Subsystem path to Windows path
583+
if runtime.GOOS == "windows" {
584+
var err error
585+
identityFile, err = ioutilx.WindowsMixedPathFromWindowsSubsystemPath(context.Background(), identityFile)
586+
if err != nil {
587+
return "", "", err
588+
}
589+
}
582590
user := findRegexpInSSHArgs(c.AdditionalArgs, regexp.MustCompile(`^User[= ]+(?:['"]?)([^'"]+)(?:['"]?)$`))
583591
if user == "" {
584592
return "", "", errors.New("failed to find User in SSHConfig.AdditionalArgs")

0 commit comments

Comments
 (0)