Skip to content

Commit

Permalink
[Java] More robust checking of symbolic links.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeb01 committed Sep 12, 2024
1 parent 2e6ffc8 commit 90f780e
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions aeron-test-support/src/main/java/io/aeron/test/DataCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.*;
Expand Down Expand Up @@ -205,36 +204,40 @@ private List<Path> findMatchingFiles(final FileFilter filter)

private static void find(final List<Path> found, final File file, final FileFilter filter)
{
try
if (existsAndIsNotSymbolicLink(file))
{
if (file.exists())
if (file.isFile())
{
final BasicFileAttributes basicFileAttributes = Files.readAttributes(
file.toPath(), BasicFileAttributes.class, NOFOLLOW_LINKS);

if (file.isFile())
if (filter.accept(file))
{
if (filter.accept(file))
{
found.add(file.toPath());
}
found.add(file.toPath());
}
else if (!basicFileAttributes.isSymbolicLink() && file.isDirectory())
}
else if (file.isDirectory())
{
final File[] files = file.listFiles();
if (null != files)
{
final File[] files = file.listFiles();
if (null != files)
for (final File f : files)
{
for (final File f : files)
{
find(found, f, filter);
}
find(found, f, filter);
}
}
}
}
catch (final IOException ex)
}

private static boolean existsAndIsNotSymbolicLink(final File file)
{
try
{
final BasicFileAttributes basicFileAttributes = Files.readAttributes(
file.toPath(), BasicFileAttributes.class, NOFOLLOW_LINKS);
return !basicFileAttributes.isSymbolicLink() && file.exists();
}
catch (IOException e)
{
throw new UncheckedIOException(ex);
return false;
}
}

Expand Down

0 comments on commit 90f780e

Please sign in to comment.