Skip to content

Commit

Permalink
Merge pull request #152 from guicamest/directoryStreamFollowSymLinks
Browse files Browse the repository at this point in the history
feat: `newDirectoryStream` follows symlinks
  • Loading branch information
marschall committed Nov 19, 2023
2 parents 14b7c51 + 67248f0 commit afdfec4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ private FileAttribute<?>[] applyUmask(FileAttribute<?>[] attributes) {
}

DirectoryStream<Path> newDirectoryStream(final AbstractPath abstractPath, final Filter<? super Path> filter) throws IOException {
return this.accessFileReading(abstractPath, false, entry -> {
return this.accessFileReading(abstractPath, true, entry -> {
if (!(entry instanceof MemoryDirectory)) {
throw new NotDirectoryException(abstractPath.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,35 @@ void directoryStreamRelative() throws IOException {

}

@Test
void directoryStreamFollowsSymlink() throws IOException {
FileSystem fileSystem = this.extension.getFileSystem();

Path root = fileSystem.getRootDirectories().iterator().next();
Path volumes = Files.createDirectory(root.resolve("Volumes"));
Path hd = Files.createSymbolicLink(volumes.resolve("Macintosh HD"), root);

Path abc = Files.createFile(root.resolve("abc.txt"));

try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(hd)) {
List<String> actual = new ArrayList<>(2);
for (Path each : directoryStream) {
actual.add(each.toRealPath().toString());
}
List<String> expected = Arrays.asList(
volumes.toRealPath().toString(),
abc.toRealPath().toString()
);
assertEquals(expected.size(), actual.size());

Set<String> actualSet = new HashSet<>(actual);
assertEquals(actualSet.size(), actual.size());

Set<String> expectedSet = new HashSet<>(expected);
assertEquals(expectedSet, actualSet);
}
}

@Test
void empty() throws IOException {
FileSystem fileSystem = this.extension.getFileSystem();
Expand Down

0 comments on commit afdfec4

Please sign in to comment.