Skip to content

Commit fd37e62

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 2fd6cc4 commit fd37e62

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
@@ -523,6 +523,14 @@ func ExecuteScriptViaInProcessClient(host string, port int, c *sshocker.SSHConfi
523523
if identityFile == "" {
524524
return "", "", errors.New("failed to find IdentityFile in SSHConfig.AdditionalArgs")
525525
}
526+
// Convert path from Windows Subsystem path to Windows path
527+
if runtime.GOOS == "windows" {
528+
var err error
529+
identityFile, err = ioutilx.WindowsMixedPathFromWindowsSubsystemPath(context.Background(), identityFile)
530+
if err != nil {
531+
return "", "", err
532+
}
533+
}
526534
user := findRegexpInSSHArgs(c.AdditionalArgs, regexp.MustCompile(`^User[= ]+(?:['"]?)([^'"]+)(?:['"]?)$`))
527535
if user == "" {
528536
return "", "", errors.New("failed to find User in SSHConfig.AdditionalArgs")

0 commit comments

Comments
 (0)