Skip to content

Commit 8a49e56

Browse files
authored
Merge pull request #108 from liketosweep/fix-msys2-paths
fix(reversesshfs): convert MSYS2 paths to native Windows paths for OpenSSH
2 parents 0ff5b47 + c786145 commit 8a49e56

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

pkg/reversesshfs/reversesshfs.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ func (rsf *ReverseSSHFS) Start() error {
133133
}
134134
if runtime.GOOS == "windows" && path.IsAbs(rsf.LocalPath) {
135135
logrus.Infof("Accepting %q Unix path, assuming Cygwin/msys2 OpenSSH", rsf.LocalPath)
136+
// Convert MSYS2 path to Windows native path
137+
rsf.LocalPath = convertMSYS2Path(rsf.LocalPath)
138+
logrus.Infof("Converted path for native Windows OpenSSH: %q", rsf.LocalPath)
136139
}
140+
137141
if !path.IsAbs(rsf.RemotePath) {
138142
return fmt.Errorf("unexpected relative path: %q", rsf.RemotePath)
139143
}
@@ -327,3 +331,14 @@ func (rsf *ReverseSSHFS) Close() error {
327331
}
328332
return nil
329333
}
334+
335+
// convertMSYS2Path converts an MSYS2 style path (e.g., /c/Users/...) to a Windows native path
336+
func convertMSYS2Path(localPath string) string {
337+
if len(localPath) >= 3 && localPath[0] == '/' && localPath[2] == '/' {
338+
driveLetter := strings.ToUpper(string(localPath[1]))
339+
// Explicitly force backslashes, bypassing WSL/Linux environment quirks
340+
remainingPath := strings.ReplaceAll(localPath[2:], "/", "\\")
341+
return driveLetter + ":" + remainingPath
342+
}
343+
return localPath
344+
}

pkg/reversesshfs/reversesshfs_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,16 @@ func TestAddQuotes(t *testing.T) {
3333
}
3434
}
3535
}
36+
37+
func TestConvertMSYS2Path(t *testing.T) {
38+
inputPath := "/c/Users/lts"
39+
expectedPath := "C:\\Users\\lts"
40+
41+
actualPath := convertMSYS2Path(inputPath)
42+
43+
if actualPath != expectedPath {
44+
t.Errorf("Conversion failed: expected %q, got %q", expectedPath, actualPath)
45+
} else {
46+
t.Logf("Success! Converted path for native Windows OpenSSH: %q", actualPath)
47+
}
48+
}

0 commit comments

Comments
 (0)