GH-3969: SFTP: Bring back support for empty path
Fixes https://github.com/spring-projects/spring-integration/issues/3969 In previous version for SFTP client (Jsch), the empty path for `LS` command has meant a `user home`. Turns out the MINA `SftpClient` does not support automatic user home resolution from the empty path. * Fix `SftpSession` to resolve an empty path into a user home via `canicalPath()` operation
This commit is contained in:
@@ -96,6 +96,7 @@ public class SftpSession implements Session<SftpClient.DirEntry> {
|
||||
remoteDir = remotePath;
|
||||
}
|
||||
}
|
||||
remoteDir = remoteDir.length() == 0 ? this.sftpClient.canonicalPath("") : remoteDir;
|
||||
return StreamSupport.stream(this.sftpClient.readDir(remoteDir).spliterator(), false)
|
||||
.filter((entry) -> !isPattern || PatternMatchUtils.simpleMatch(remoteFile, entry.getFilename()));
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.springframework.integration.file.DefaultFileNameGenerator;
|
||||
import org.springframework.integration.file.remote.ClientCallbackWithoutResult;
|
||||
import org.springframework.integration.file.remote.SessionCallbackWithoutResult;
|
||||
import org.springframework.integration.file.remote.session.CachingSessionFactory;
|
||||
import org.springframework.integration.file.remote.session.Session;
|
||||
import org.springframework.integration.file.remote.session.SessionFactory;
|
||||
import org.springframework.integration.file.support.FileExistsMode;
|
||||
import org.springframework.integration.sftp.SftpTestSupport;
|
||||
@@ -124,6 +125,14 @@ public class SftpRemoteFileTemplateTests extends SftpTestSupport {
|
||||
sessionFactory.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lsUserHome() throws IOException {
|
||||
try (Session<SftpClient.DirEntry> session = this.sessionFactory.getSession()) {
|
||||
String[] entries = session.listNames("");
|
||||
assertThat(entries).contains(".", "sftpSource", "sftpTarget");
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class Config {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user