Skip to content

Commit f2399a4

Browse files
committed
GH-9268: Fix regression in SMB Inbound for sub-dirs
Fixes: #9268 The new `SmbSession.list()` behavior prevents to pull files from sub-folders in inbound channel adapter * Fix `SmbSession.list()` similar way to `SftpSession`: if `remoteFile.isFile()` then remove it as is. Otherwise, perform `smbDir.listFiles()` on that sub-dir * Modify `SmbTests.testSmbInboundFlow()` to poll files from the `smbSource/subSmbSource/` **Auto-cherry-pick to `6.3.x` & `6.2.x`**
1 parent 981f576 commit f2399a4

File tree

2 files changed

+14
-12
lines changed
  • spring-integration-smb/src

2 files changed

+14
-12
lines changed

spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbSession.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,25 +119,26 @@ public boolean remove(String _path) throws IOException {
119119
}
120120

121121
/**
122-
* Return the contents of the specified SMB resource as an array of SmbFile objects.
122+
* Return the content of the specified SMB resource as an array of SmbFile objects.
123123
* In case the remote resource does not exist, an empty array is returned.
124-
* @param remotePath path to a remote directory or remote file path
124+
* @param path path to a remote directory or remote file path
125125
* @return array of SmbFile objects
126-
* @throws IOException on error conditions returned by a CIFS server or if the remote resource is not a directory.
126+
* @throws IOException on error conditions returned by a CIFS server.
127127
*/
128128
@Override
129-
public SmbFile[] list(String remotePath) throws IOException {
130-
SmbFile[] files;
129+
public SmbFile[] list(String path) throws IOException {
130+
String remotePath = StringUtils.trimTrailingCharacter(path, '/');
131+
SmbFile[] files = null;
131132
int lastIndex = StringUtils.hasText(remotePath) ? remotePath.lastIndexOf('/') : 0;
132133
String remoteFileName = lastIndex > 0 ? remotePath.substring(lastIndex + 1) : null;
133134
if (StringUtils.hasText(remoteFileName)) {
134135
SmbFile remoteFile = createSmbFileObject(remotePath);
135-
if (!remoteFile.isFile()) {
136-
throw new IOException("[" + remotePath + "] is not a file.");
136+
if (remoteFile.isFile()) {
137+
files = new SmbFile[] {remoteFile};
137138
}
138-
files = new SmbFile[] {remoteFile};
139139
}
140-
else {
140+
141+
if (files == null) {
141142
try {
142143
SmbFile smbDir = createSmbDirectoryObject(remotePath);
143144
if (!smbDir.exists()) {
@@ -154,6 +155,7 @@ else if (!smbDir.isDirectory()) {
154155
throw new IOException("Failed to list in [" + remotePath + "].", _ex);
155156
}
156157
}
158+
157159
logListedFiles(remotePath, files);
158160

159161
return files;

spring-integration-smb/src/test/java/org/springframework/integration/smb/dsl/SmbTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void testSmbInboundFlow() {
9292
DirectoryScanner scanner = new DefaultDirectoryScanner();
9393
IntegrationFlow flow = IntegrationFlow.from(Smb.inboundAdapter(sessionFactory())
9494
.preserveTimestamp(true)
95-
.remoteDirectory("smbSource")
95+
.remoteDirectory("smbSource/subSmbSource/")
9696
.maxFetchSize(10)
9797
.scanner(scanner)
9898
.regexFilter(".*\\.txt$")
@@ -115,13 +115,13 @@ public void testSmbInboundFlow() {
115115
Object payload = message.getPayload();
116116
assertThat(payload).isInstanceOf(File.class);
117117
File file = (File) payload;
118-
assertThat(file.getName()).isIn("SMBSOURCE1.TXT.a", "SMBSOURCE2.TXT.a");
118+
assertThat(file.getName()).isEqualTo("SUBSMBSOURCE1.TXT.a", "SUBSMBSOURCE2.TXT.a");
119119
assertThat(file.getAbsolutePath()).contains("localTarget");
120120

121121
message = out.receive(10_000);
122122
assertThat(message).isNotNull();
123123
file = (File) message.getPayload();
124-
assertThat(file.getName()).isIn("SMBSOURCE1.TXT.a", "SMBSOURCE2.TXT.a");
124+
assertThat(file.getName()).isIn("SUBSMBSOURCE1.TXT.a", "SUBSMBSOURCE2.TXT.a");
125125
assertThat(file.getAbsolutePath()).contains("localTarget");
126126

127127
assertThat(out.receive(10)).isNull();

0 commit comments

Comments
 (0)