Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -692,21 +692,16 @@ private BiPredicate<Path, BasicFileAttributes> createFileFilter(final ProcessCon
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,40 @@ public void testFilterPathPattern() throws Exception {
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();
Expand Down