Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Objects;
Expand Down Expand Up @@ -126,7 +127,7 @@ public Set<String> listNames(String regex) throws IOException {
// Consider only files in the given folder, do not go into folders
Pattern p = Pattern.compile(regex);
int maxDepth = 1;
try (Stream<Path> paths = Files.walk(directory, maxDepth)) {
try (Stream<Path> paths = Files.walk(directory, maxDepth, FileVisitOption.FOLLOW_LINKS)) {
var filenames = paths
.filter(Files::isRegularFile)
.map(Path::getFileName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* @author Nicolas Rol {@literal <nicolas.rol at rte-france.com>}
Expand Down Expand Up @@ -169,4 +171,24 @@ protected DirectoryDataSource createDataSourceForPolynomialRegexTest() throws IO
Files.createFile(testDir.resolve(filename));
return new DirectoryDataSource(testDir, "");
}

@Test
void testSymbolicLink() throws IOException {
// Create a folder with a file
Path realPath = testDir.resolve("realPath");
Files.createDirectories(realPath);
Files.createFile(fileSystem.getPath(realPath + "/test_file.txt"));

// Create a symbolic link to the real path
Path symbolicPath = testDir.resolve("symbolicPath");
Files.createSymbolicLink(symbolicPath, realPath);

// Create two data sources
DirectoryDataSource datasourceOnRealPath = new DirectoryDataSource(realPath, "test_file");
DirectoryDataSource datasourceOnSymbolicPath = new DirectoryDataSource(symbolicPath, "test_file");
assertEquals(1, datasourceOnRealPath.listNames(".*").size());
assertEquals(1, datasourceOnSymbolicPath.listNames(".*").size());
assertTrue(datasourceOnRealPath.listNames(".*").contains("test_file.txt"));
assertTrue(datasourceOnSymbolicPath.listNames(".*").contains("test_file.txt"));
}
}