Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IO-789 Symbolic link file filter accepts all files, not just symbolic links #449

Closed
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}