GH-3482: (S)FTP: Fix Recursive LS (ARFOG)
Resolves https://github.com/spring-projects/spring-integration/issues/3482 `.` and `..` should be ignored when recursing. **cherry-pick to 5.4.x, 5.3.x** * Fix checkstyle. * Fix test in `file` module - test was incorrect; it would have detected this problem.
This commit is contained in:
@@ -974,18 +974,23 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
|
||||
private void processFile(Session<F> session, String directory, String subDirectory, List<F> lsFiles,
|
||||
boolean recursion, F file) throws IOException {
|
||||
|
||||
String fileName = getFilename(file);
|
||||
String fileSep = this.remoteFileTemplate.getRemoteFileSeparator();
|
||||
boolean isDots = ".".equals(fileName)
|
||||
|| "..".equals(fileName)
|
||||
|| fileName.endsWith(fileSep + ".")
|
||||
|| fileName.endsWith(fileSep + "..");
|
||||
if (this.options.contains(Option.SUBDIRS) || !isDirectory(file)) {
|
||||
if (recursion && StringUtils.hasText(subDirectory)) {
|
||||
if (recursion && StringUtils.hasText(subDirectory) && (!isDots || this.options.contains(Option.ALL))) {
|
||||
lsFiles.add(enhanceNameWithSubDirectory(file, subDirectory));
|
||||
}
|
||||
else {
|
||||
else if (this.options.contains(Option.ALL) || !isDots) {
|
||||
lsFiles.add(file);
|
||||
}
|
||||
}
|
||||
String fileName = getFilename(file);
|
||||
if (recursion && isDirectory(file) && !(".".equals(fileName)) && !("..".equals(fileName))) {
|
||||
if (recursion && isDirectory(file) && !isDots) {
|
||||
lsFiles.addAll(listFilesInRemoteDir(session, directory,
|
||||
subDirectory + fileName + this.remoteFileTemplate.getRemoteFileSeparator()));
|
||||
subDirectory + fileName + fileSep));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user