NIFI-9996 - ListFile does not list root directory when Recurse Subdirectories is active and Path Filter is specified (#6110)

This commit is contained in:
greyp9 2022-06-21 17:23:49 -04:00 committed by GitHub
parent c08996515b
commit f9beb507fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 10 deletions

View File

@ -692,21 +692,16 @@ public class ListFile extends AbstractListProcessor<FileInfo> {
return false;
}
final Path relativePath = basePath.relativize(path).getParent();
final String relativeDir = relativePath == null ? "" : relativePath.toString();
final Path relativePath = basePath.relativize(path);
final Path relativePathParent = relativePath.getParent();
final String relativeDir = relativePathParent == null ? "" : relativePathParent.toString();
final String filename = path.getFileName().toString();
final TimingInfo timingInfo = performanceTracker.getTimingInfo(relativeDir, filename);
final File file = path.toFile();
if (pathPattern != null) {
if (relativePath == null || relativePath.toString().isEmpty()) {
return false;
}
if (!pathPattern.matcher(relativePath.toString()).matches()) {
return false;
}
if ((pathPattern != null) && (!pathPattern.matcher(relativeDir).matches())) {
return false;
}
final boolean matchesFilter = filePattern.matcher(filename).matches();

View File

@ -694,6 +694,40 @@ public class TestListFile {
assertEquals(1, successFiles3.size());
}
@Test
public void testFilterPathPatternNegative() throws Exception {
final long now = getTestModifiedTime();
final File subdirA = new File(TESTDIR + "/AAA");
assertTrue(subdirA.mkdirs());
final File subdirL = new File(TESTDIR + "/LOG");
assertTrue(subdirL.mkdirs());
final File file1 = new File(TESTDIR + "/file1.txt");
assertTrue(file1.createNewFile());
assertTrue(file1.setLastModified(now));
final File file2 = new File(TESTDIR + "/AAA/file2.txt");
assertTrue(file2.createNewFile());
assertTrue(file2.setLastModified(now));
final File file3 = new File(TESTDIR + "/LOG/file3.txt");
assertTrue(file3.createNewFile());
assertTrue(file3.setLastModified(now));
runner.setProperty(ListFile.DIRECTORY, testDir.getAbsolutePath());
runner.setProperty(ListFile.FILE_FILTER, ListFile.FILE_FILTER.getDefaultValue());
runner.setProperty(ListFile.PATH_FILTER, "^((?!LOG).)*$");
runner.setProperty(ListFile.RECURSE, "true");
assertVerificationOutcome(Outcome.SUCCESSFUL, "Successfully listed .* Found 3 objects. Of those, 2 match the filter.");
runNext();
runner.assertAllFlowFilesTransferred(ListFile.REL_SUCCESS);
final List<MockFlowFile> successFiles1 = runner.getFlowFilesForRelationship(ListFile.REL_SUCCESS);
assertEquals(2, successFiles1.size());
}
@Test
public void testRecurse() throws Exception {
final long now = getTestModifiedTime();