GH-11121: Fix SftpSession.listNames() for root directory wildcard paths#11122
GH-11121: Fix SftpSession.listNames() for root directory wildcard paths#11122yangadam wants to merge 1 commit into
Conversation
artembilan
left a comment
There was a problem hiding this comment.
Well, looks like you have not checked the fix locally before opening PR:
SftpOutboundTests > testFtpOutboundGatewayInsideChain() FAILED
org.springframework.messaging.MessageHandlingException at SftpOutboundTests.java:192
Caused by: org.springframework.messaging.MessagingException at SftpOutboundTests.java:192
Caused by: java.lang.NullPointerException at SftpOutboundTests.java:192
Please, ensure you run ./gradlew "spring-integration-sftp:check locally before pushing to PR.
Thanks
Thanks for running the build. After debugging, I found that the failure was caused by the lack of mocking for the I can add the mocking, but I need to confirm whether it is acceptable to call |
…ry wildcard paths
Change `lastIndex > 0` to `lastIndex >= 0` in `SftpSession.doList()` so
that root-level paths like `/*` are correctly split into directory and
file components. Previously, `lastIndexOf('/')` returning `0` was not
handled, causing the entire path to be treated as a directory name.
Fixes: spring-projectsgh-11121
Signed-off-by: Adam Yang <yangmm.adam@gmail.com>
artembilan
left a comment
There was a problem hiding this comment.
I need to confirm whether it is acceptable to call stat whenever the path is
/remote-test-dir/or/remote-test-dir/remote-sub-dir/.
Correct. So, ask yourself if it is valid to divide /remote-test-dir into / and remote-test-dir as you do in your current fix.
You covered with boolean isPattern = remoteFile != null && remoteFile.contains("*");.
But that is not OK for a dir request.
I think we need just trim both leading and trailing / in the method you have modified instead.
Something like:
String remotePath = StringUtils.trimLeadingCharacter(StringUtils.trimTrailingCharacter(validPath, '/'), '/');
With that your /* will become * as you expect.
|
Hi @artembilan, thanks for taking the time to review and for the suggestion! I looked into the trimming approach, but I think the split-then-stat pattern might actually be unavoidable here. A name like In fact, the existing code on main already does this for deeper paths. For example,
My fix for Would it be OK to keep this approach consistent with the existing behavior for now, and refactor the method later if we'd like to optimize it? |
artembilan
left a comment
There was a problem hiding this comment.
Please, add your name to the @author list of all the affected classes.
Then we'll merge.
Thank you!
Summary
SftpSession.listNames("/*")throwsSftpException: SSH_FX_NO_SUCH_FILEbecause the path parsing inSftpSession.list()useslastIndex > 0to detect the/separator. For root-level paths like/*,lastIndexOf('/')returns0, which is excluded by the> 0check. This causes the entire path/*to be treated as a literal directory name instead of being split into directory/and file pattern*.Changes
lastIndex > 0tolastIndex >= 0inSftpSession.list()so root directory paths are correctly parsedlsRootWildcard()that reproduces the issue and verifies the fixFixes: gh-11121
Signed-off-by: Adam Yang yangadam@users.noreply.github.com