mirror of
https://github.com/apache/nifi.git
synced 2025-03-06 09:29:33 +00:00
NIFI-9996 - ListFile does not list root directory when Recurse Subdirectories is active and Path Filter is specified (#6110)
This commit is contained in:
parent
c08996515b
commit
f9beb507fd
@ -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();
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user