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:
abilan
2022-12-12 10:27:05 -05:00
committed by Gary Russell
parent 6fd4fd3dd9
commit 1c836f0698
2 changed files with 10 additions and 0 deletions

View File

@@ -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()));
}

View File

@@ -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 {