Skip to content

Commit

Permalink
[Java] Ensure that DataCollector does not traverse symbolic links whe…
Browse files Browse the repository at this point in the history
…n finding files.
  • Loading branch information
mikeb01 committed Sep 12, 2024
1 parent 9a720d0 commit 2e6ffc8
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 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,12 +22,14 @@
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.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate;

import static java.nio.file.LinkOption.NOFOLLOW_LINKS;
import static java.nio.file.StandardCopyOption.COPY_ATTRIBUTES;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -203,27 +205,37 @@ private List<Path> findMatchingFiles(final FileFilter filter)

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

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

public String toString()
Expand Down

0 comments on commit 2e6ffc8

Please sign in to comment.