fix(reversesshfs): convert MSYS2 paths to native Windows paths for OpenSSH#108
fix(reversesshfs): convert MSYS2 paths to native Windows paths for OpenSSH#108liketosweep wants to merge 1 commit into
Conversation
Signed-off-by: liketosweep <liketosweep@gmail.com>
|
Thanks, could you share how you tested these changes? |
|
Hi @unsuman, I’ve validated this patch natively on a Windows host using the Testing Methodology: Environment: Windows host, Lima v2.1.1, QEMU driver, and Git's OpenSSH client. Action: Swapped in the compiled, patched sshocker.exe and launched an Ubuntu guest with a reverse SSHFS mount targeting my local Windows directory (C:/Users/lts). Results: Validation Evidence:Host Agent Logs (Confirming successful path translation and
Guest Shell Output (Confirming read access to the mounted Windows directory via
Let me know if you need any further testing or logs for this PR! |
|
I wonder if we should have this change inside Lima itself, which lima-vm/lima#4885 already does and solve the chdir issue But this issue still persists: |
|
Thank you for the feedback, @unsuman. Regarding Redundancy with #4885I agree that centralizing the path normalization logic natively within the core Lima codebase (#4885) is the superior architectural approach. If we are confident that the implementation in #4885 covers these specific OpenSSH pathing requirements for Windows hosts, I am happy to close this PR to avoid logic fragmentation. Regarding the
|
There was a problem hiding this comment.
Pull request overview
This PR fixes reverse SSHFS mounting on Windows hosts by converting MSYS2/Cygwin-style Unix paths (e.g., /c/Users/<user>) into native Windows paths (e.g., C:\Users\<user>) before invoking the mount flow, addressing failures caused by passing unconverted paths into Windows OpenSSH.
Changes:
- Convert MSYS2-style
/X/...local paths toX:\...duringReverseSSHFS.Start()on Windows. - Add a unit test to validate the MSYS2-to-Windows path conversion behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/reversesshfs/reversesshfs.go | Adds convertMSYS2Path() and applies it to Windows-local Unix absolute paths before starting sshfs/sftp-server. |
| pkg/reversesshfs/reversesshfs_test.go | Adds a test for MSYS2 path conversion. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| func convertMSYS2Path(localPath string) string { | ||
| if len(localPath) >= 3 && localPath[0] == '/' && localPath[2] == '/' { | ||
| driveLetter := strings.ToUpper(string(localPath[1])) | ||
| // Explicitly force backslashes, bypassing WSL/Linux environment quirks | ||
| remainingPath := strings.ReplaceAll(localPath[2:], "/", "\\") | ||
| return driveLetter + ":" + remainingPath | ||
| } | ||
| return localPath | ||
| } |
| func TestConvertMSYS2Path(t *testing.T) { | ||
| inputPath := "/c/Users/lts" | ||
| expectedPath := "C:\\Users\\lts" | ||
|
|
||
| actualPath := convertMSYS2Path(inputPath) | ||
|
|
||
| if actualPath != expectedPath { | ||
| t.Errorf("Conversion failed: expected %q, got %q", expectedPath, actualPath) | ||
| } else { | ||
| t.Logf("Success! Converted path for native Windows OpenSSH: %q", actualPath) | ||
| } | ||
| } |



What the Issue Was
Reverse SSHFS mounting of the Windows home directory fails on Lima/QEMU
(Windows host) with a
Permission deniederror. The hostagent accepts theMSYS2-style Unix path (
/c/Users/<user>) emitted by Cygwin/msys2 OpenSSHbut forwards it unconverted to the mount layer, which expects a native
Windows path (
C:\Users\<user>). This causeschdirto fail withNo such file or directory, cascading into afusermount3mount failure.The issue is reproducible locally and in CI.
Why It Was There
reversesshfs.gohad detection logic for MSYS2/Cygwin-style paths onruntime.GOOS == "windows"but no subsequent conversion step. Once thepath was identified as MSYS2 format, it was logged and passed through
as-is — Windows OpenSSH has no awareness of the MSYS2 path convention
and cannot resolve
/c/Users/...as a valid filesystem location.Solution
Introduced
convertMSYS2Path(localPath string) stringinreversesshfs.go.The function targets the MSYS2 drive-letter convention — a path of the form
/X/...whereXis a single alphabetic character — extracts and uppercasesthe drive letter, appends
:, and rewrites the remainder with backslashseparators, bypassing WSL/Linux environment path quirks entirely. Paths that
do not conform to this pattern are returned unchanged, ensuring no unintended
side effects on non-Windows or already-native paths.
The function is invoked within
Start()immediately after MSYS2 pathdetection, replacing
rsf.LocalPathwith the converted Windows-nativeequivalent before the mount is attempted. The converted path is logged
for traceability.
Changes
pkg/reversesshfs/reversesshfs.go— AddedconvertMSYS2Path()andintegrated it into the Windows path detection block in
Start(), witha log line confirming the resolved native path.
pkg/reversesshfs/reversesshfs_test.go— AddedTestConvertMSYS2Pathasserting that
/c/Users/ltscorrectly resolves toC:\\Users\\lts,with explicit failure messaging on mismatch.
Result
The hostagent now correctly resolves MSYS2-style paths to their Windows-native
equivalents before invoking OpenSSH, eliminating the
chdirfailure andrestoring reliable reverse SSHFS mounting on Windows/QEMU — both locally
and in CI.
Fixes #4810