SFTPClient treats relative paths that do not start with a dot as absolute paths
- Dominant language
- Java
- Stars
- 2.7k
- Forks
- 620
- Avg merge
- 3d 23h
- Merged PRs (30d)
- 11
Description
Version discovered: 0.8.1
#### Observation
When dealing with relative paths that do not start with `./`, such as `myFolder` (instead of `./myFolder`), the `SFTPClient` treats the path as absolute:
`SftpClient.mkDirs("myFolder")` creates `C:\myFolder` on a Windows machine and fails on Linux due to a lack of permissions to create `/myFolder`.
This is a regression from 0.7.0, where the client was still creating the relative folder as expected.
We can observe similar behaviour with other SFTP commands that operate on paths.
#### Analysis
It appears that `PathComponents.adjustForParent()` is responsible for this problem, as it adds a leading `/` to the relative path even if the parent path is empty, e.g. converting
```
parent = ""
name = "myFolder"
```
to
```
path = "/myFolder"
```
#### Attempted Fix
We (that is, @signed and me) tried to come up with a patch, but could not figure out how to.
For one, `PathComponents` are widely used and we could not foresee the consequences of a seemingly small change, moreover, the information about the path's absoluteness is stripped (in `PathHelper.getComponents`) before we enter the relevant method, effectively making `/myFolder` indiscernible from `myFolder`.
#### Workaround
As a workaround, we prepend `./` in front of every relative path we hand to the `SFTPClient`.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.