patches/0004: resolve NTFS symlink at readdir root before walkFileTree - #11
Merged
Merged
Conversation
Ilia (k15tfu)
requested changes
May 1, 2026
Mikhail Filippov (mfilippov)
force-pushed
the
fix-readdir-symlink-on-windows
branch
from
May 1, 2026 17:58
27489ad to
a4b5162
Compare
Files.walkFileTree(NOFOLLOW) treats an NTFS symbolic link to a directory
as a file: it calls visitFile on the link instead of preVisitDirectory,
so the children of the link target are never enumerated. The patched
WindowsFileSystem#readdir then returns a single Dirent for the link
itself, and any glob() over a package whose subdirectories are NTFS
symlinks (e.g. external/llvm++llvm_source+libcxx{,abi}, where src/,
include/, etc. are symlinks into llvm-raw) silently matches nothing
and trips --incompatible_disallow_empty_glob.
Resolve the link with toRealPath() unconditionally: readdir's contract
follows symlinks when resolving the directory itself regardless of
followSymlinks (which only governs entry types). Junctions are not
recognized as symlinks here and report isDirectory()==true natively,
so they're unaffected; the extra Files.isSymbolicLink() check is one
GetFileAttributes call per readdir.
Ilia (k15tfu)
force-pushed
the
fix-readdir-symlink-on-windows
branch
from
May 2, 2026 10:45
a4b5162 to
47ee50f
Compare
Ilia (k15tfu)
approved these changes
May 2, 2026
| + } | ||
| + | ||
| + @Override | ||
| + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) { |
Collaborator
There was a problem hiding this comment.
from https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html:
The visitFile method is invoked for all files, including directories, encountered at maxDepth, unless the basic file attributes cannot be read, in which case the visitFileFailed method is invoked.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Files.walkFileTree(NOFOLLOW) treats an NTFS symbolic link to a directory as a file: it calls visitFile on the link instead of preVisitDirectory, so the children of the link target are never enumerated. The patched WindowsFileSystem#readdir then returns a single Dirent for the link itself, and any glob() over a package whose subdirectories are NTFS symlinks (e.g. external/llvm++llvm_source+libcxx{,abi}, where src/, include/, etc. are symlinks into llvm-raw) silently matches nothing and trips --incompatible_disallow_empty_glob.
Resolve the link with toRealPath() when called with NOFOLLOW. Junctions report isDirectory()==true under NOFOLLOW and are unaffected; the extra Files.isSymbolicLink() check is one GetFileAttributes call per readdir.