Skip to content

Commit 4fa9d42

Browse files
committed
[IO-875] CopyDirectoryVisitor ignores fileFilter #743
- Document adding and using org.apache.commons.io.file.CountingPathVisitor.accept(Path, BasicFileAttributes) #743 - Added missing Javadoc since tag - Fix Javadoc comment - Remove extra blank lines - Sort members
1 parent 5bcc9a8 commit 4fa9d42

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/changes/changes.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ The <action> type attribute can be add,update,fix,remove.
4545
<title>Apache Commons IO Release Notes</title>
4646
</properties>
4747
<body>
48-
<release version="2.19.1" date="YYYY-MM-DD" description="Version 2.19.1: Java 8 or later is required.">
48+
<release version="2.20.0" date="YYYY-MM-DD" description="Version 2.19.1: Java 8 or later is required.">
4949
<!-- FIX -->
5050
<action dev="ggregory" type="fix" due-to="Jesse Glick">[javadoc] Rename parameter of ProxyOutputStream.write(int) #740.</action>
51+
<action dev="ggregory" type="fix" issue="IO-875" due-to="Pierre Baumard, Gary Gregory">CopyDirectoryVisitor ignores fileFilter #743.</action>
5152
<!-- ADD -->
53+
<action dev="ggregory" type="add" issue="IO-875" due-to="Pierre Baumard, Gary Gregory">Add and use org.apache.commons.io.file.CountingPathVisitor.accept(Path, BasicFileAttributes) #743.</action>
5254
<!-- UPDATE -->
5355
</release>
5456
<release version="2.19.0" date="2025-04-08" description="Version 2.19.0: Java 8 or later is required.">

src/main/java/org/apache/commons/io/file/CountingPathVisitor.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,19 @@ public CountingPathVisitor(final PathCounters pathCounters, final PathFilter fil
236236
this.directoryPostTransformer = UnaryOperator.identity();
237237
}
238238

239+
/**
240+
* Tests whether the given file is accepted by the file filter.
241+
*
242+
* @param file the visited file.
243+
* @param attributes the visited file attributes.
244+
* @return true to copy the given file, false if not.
245+
* @since 2.20.0
246+
*/
247+
protected boolean accept(final Path file, final BasicFileAttributes attributes) {
248+
// Note: A file can be a symbolic link to a directory.
249+
return Files.exists(file) && fileFilter.accept(file, attributes) == FileVisitResult.CONTINUE;
250+
}
251+
239252
@Override
240253
public boolean equals(final Object obj) {
241254
if (this == obj) {
@@ -290,18 +303,6 @@ protected void updateDirCounter(final Path dir, final IOException exc) {
290303
pathCounters.getDirectoryCounter().increment();
291304
}
292305

293-
/**
294-
* Returns true to copy the given file, false if not.
295-
*
296-
* @param file the visited file.
297-
* @param attributes the visited file attributes.
298-
* @return true to copy the given file, false if not.
299-
*/
300-
protected boolean accept(final Path file, final BasicFileAttributes attributes) {
301-
// Note: A file can be a symbolic link to a directory.
302-
return Files.exists(file) && fileFilter.accept(file, attributes) == FileVisitResult.CONTINUE;
303-
}
304-
305306
/**
306307
* Updates the counters for visiting the given file.
307308
*

src/test/java/org/apache/commons/io/file/CopyDirectoryVisitorTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ public void testCopyDirectoryFilters(final PathCounters pathCounters) throws IOE
118118
assertFalse(Files.exists(targetDir.resolve("dirs-a-file-size-2")));
119119
}
120120

121-
122121
/**
123122
* Tests a directory with one file of size 0.
124123
*/

0 commit comments

Comments
 (0)