rsync -e flag causes path misread with /c/ paths (source and destination cannot both be remote)
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 240
- Forks
- 60
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 1
Description
Description
When using MSYS2 rsync (rsync 3.4.1 from Git for Windows) with the -e flag and a remote destination containing an MSYS2-style path (e.g., /c/Users/...), rsync fails with:
rsync error: syntax or usage error (code 1) at main.c(1415) [Receiver=3.4.1] - The source and destination cannot both be remote.
This happens because MSYS2 path conversion converts the /c/ portion of the remote destination path (user@host:/c/path) and rsync then misinterprets the remote path as a local path, triggering the error.
Steps to Reproduce
On a Windows machine with Git for Windows (MSYS2 rsync):
# FAILS with 'source and destination cannot both be remote':
rsync -az -e "ssh -p 2222" "/c/Users/test/file.txt" "user@host:/c/Users/test/"
# WORKS correctly (using RSYNC_RSH env var instead of -e flag):
RSYNC_RSH="ssh -p 2222" rsync -az "/c/Users/test/file.txt" "user@host:/c/Users/test/"
Note: The remote side must have rsync installed (e.g., cwrsync) for the connection to succeed once the path bug is bypassed.
Expected Behavior
Both invocation styles (-e flag and RSYNC_RSH env var) should behave identically. The -e flag should pass the remote path unchanged to SSH/rsync on the remote side.
Root Cause Analysis
The issue appears to be in how MSYS2's path conversion layer handles arguments when rsync spawns the remote shell via -e. When the remote path argument containing /c/ (MSYS2 Windows drive path format) is passed through the MSYS2 runtime's spawn() or exec() call, the path conversion converts the /c/ portion before rsync can pass it to the SSH process unchanged. This causes rsync to misinterpret user@host:/c/path as having a local path component.
Workaround
Use RSYNC_RSH environment variable instead of the -e flag:
export RSYNC_RSH="ssh -p 2222 -i /c/Users/.ssh/id_rsa"
rsync -az /c/Users/local/path/ user@host:/c/Users/remote/path/
Environment
- OS: Windows 10/Server (MSYS2/Git for Windows)
- rsync: 3.4.1 (from Git for Windows bundled MSYS2)
- SSH: OpenSSH_for_Windows_9.x
- MSYS2 runtime version: (please fill in)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failing and working commands, then inspect the MSYS2 runtime path-conversion behavior around spawn()/exec() when rsync uses -e. Compare that path with the RSYNC_RSH case and verify that user@host:/c/path reaches SSH unchanged and no longer triggers the source-and-destination error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, shell
- Domain
- cli, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100