Repository navigation
Fix GetCanonicalPathAsync resolving full path instead of parent - #1864
Conversation
|
Thanks, I have tried to avoid understanding this part of the code in the past but the sync/async paths are clearly inconsistent, seems it was an accident in 508fc87. I've taken the liberty of combining the whole thing into a shared method. I thought about adding an integration test but it seems like it is quite hard to hit this depending on the server behaviour of SSH_FXP_REALPATH, but if you have a straightforward case then we can add it. |
There was a problem hiding this comment.
🟡 Changes recommended
A regression test is still needed for the parent-path fallback in both GetCanonicalPath and GetCanonicalPathAsync to guard against the original full-path retry bug.
1 open issue
What changed in this PR
This PR addresses #1863 by aligning SSH.NET’s synchronous and asynchronous SFTP path canonicalization so failed full-path lookups fall back to resolving the parent directory.
Changes:
- Share canonicalization logic between sync and async methods.
- Correct the async fallback to resolve the parent and append the final path component.
- Avoid allocating a string for ordinal character searches in the compatibility helper.
| File | Description |
|---|---|
src/Renci.SshNet/Sftp/SftpSession.cs |
Unifies canonicalization logic and corrects the async parent-path fallback. |
src/Renci.SshNet/Abstractions/StringExtensions.cs |
Optimizes ordinal character searches using IndexOf(char). |
Review effort: Balanced

Fixes #1863
First time contributing to this project, relatively trivial, but still a bug I think worth fixing. Discovered this issue when looking at MoveTo vs RenameAsync; I've made the relevant change and tried to adhere to the standards/contributing docs; let me know if I've missed something.
The fix itself just moves the problematic implementation details into shared methods (because they previously differ); I've added some tests again trying to adhere to the style in the project.
AI not used to write the change.