slankka commented on a change in pull request #15999:
URL: https://github.com/apache/flink/pull/15999#discussion_r757843035
##########
File path: flink-core/src/test/java/org/apache/flink/util/FileUtilsTest.java
##########
@@ -331,6 +331,22 @@ public void testListAFileFailsBecauseDirectoryIsExpected()
throws IOException {
FileUtils.listFilesInDirectory(file.toPath(), FileUtils::isJarFile);
}
+ @Test
+ public void testFollowSymbolicLink() throws IOException {
+ final String fileName = "a/a.jar";
+ File folder = tmp.newFolder("a");
+ final File file = tmp.newFile(fileName);
+
+ java.nio.file.Path linkPath = Paths.get(folder.getParent(), "a.lnk");
+ Files.createSymbolicLink(linkPath, file.getParentFile().toPath());
+ Collection<java.nio.file.Path> paths =
+ FileUtils.listFilesInDirectory(linkPath.toRealPath(),
FileUtils::isJarFile);
Review comment:
I have already changed test code to prove it. Here are my thoughts:
* `listFilesInDirectory` resolves symbolic links for files under given path
which name is still symbolic.
* `toRealPath` resolves the top symbolic path only.
This is the reason I still using `toRealPath` for `listFilesInDirectory`'s
first argument in `YarnApplicationFileUploader`.
if not using `toRealPath`, `listFilesInDirectory` returns:
```a.lnk/a.jar```
It not easy to write unit test code with `verifyDirectoryRecursive` or full
path validation.
```a/a.jar```
May be I should change `FileUtils.listFilesInDirectory` like this:
```
Files.walkFileTree(
directory, // -> directory.toRealPath()
EnumSet.of(FileVisitOption.FOLLOW_LINKS),
Integer.MAX_VALUE,
filterFileVisitor);
```
For now, it doesn't affect the files we finally get, but the paths aren't
identical.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]