diff --git a/src/main/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.java b/src/main/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.java index 6dee2699898..05d55bcf9b8 100644 --- a/src/main/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.java +++ b/src/main/java/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.java @@ -87,25 +87,37 @@ public SymbolicLinkFileFilter(final FileVisitResult onAccept, final FileVisitRes } /** - * Checks to see if the file is a file. + * Checks to see if the file is a symbolic link. * * @param file the File to check - * @return true if the file is a file + * @return true if the file exists and is a symbolic link to either another file or a directory, + * false otherwise. */ @Override public boolean accept(final File file) { - return file.isFile(); + return isSymbolicLink(file.toPath()); } /** - * Checks to see if the file is a symbolic link. - * @param file the File to check + * Checks to see if the file is a file. * - * @return true if the file is a symbolic link. + * @param path the File Path to check + * @return true if the file exists and is a symbolic link to either another file or a directory. */ @Override - public FileVisitResult accept(final Path file, final BasicFileAttributes attributes) { - return toFileVisitResult(Files.isSymbolicLink(file)); + public FileVisitResult accept(final Path path, final BasicFileAttributes attributes) { + return toFileVisitResult(isSymbolicLink(path)); } + /** + * Package access, so the unit test may override to mock it. To + * facilitate unit testing, all calls to test if the file is a symbolic should go + * through this method. (See the unit test for why.) + * + * @param filePath The filePath to test + * @return true if the file exists and is a symbolic link to either a file or directory, false otherwise. + */ + boolean isSymbolicLink(Path filePath) { + return Files.isSymbolicLink(filePath); + } }