[BUG] filesystem: skip symbolic links instead of aborting#1338
Open
CybotTM wants to merge 2 commits intophpDocumentor:mainfrom
Open
[BUG] filesystem: skip symbolic links instead of aborting#1338CybotTM wants to merge 2 commits intophpDocumentor:mainfrom
CybotTM wants to merge 2 commits intophpDocumentor:mainfrom
Conversation
`FlySystemAdapter::createForPath()` instantiates the Local/Flysystem adapter with the default link-handling mode, which is `DISALLOW_LINKS` in both `league/flysystem` v1 (`Adapter\Local`) and v3 (`Local\LocalFilesystemAdapter`). When the adapter's `listContents()` encounters any symbolic link during directory traversal it throws — v1: `League\Flysystem\NotSupportedException`, v3: `League\Flysystem\SymbolicLinkEncountered` — aborting the whole render. Concrete consumer impact ------------------------ `phpDocumentor\Guides\Handlers\ParseDirectoryHandler` calls `FlySystemAdapter::listContents()` to find the entrypoint of an input directory. A single symlink anywhere in the input tree kills the run, even for symlinks that point to files the parser would ignore anyway (e.g. `CLAUDE.md -> AGENTS.md` for AI tooling, vendored references, build artefacts). Downstream report in the TYPO3 render-guides wrapper: TYPO3-Documentation/render-guides#1234 Fix --- Pass `SKIP_LINKS` as the link-handling constructor argument to both the v1 and v3 Local adapters. This preserves the current "do not follow links" posture but turns an abort into a silent skip — aligning with how most documentation builders treat filesystem entries they can't or shouldn't parse. - v1: `new Local($path, LOCK_EX, Local::SKIP_LINKS)` (positional, since v1's constructor predates named args; `LOCK_EX` is the library's own default for `$writeFlags`). - v3: `new LocalFilesystemAdapter($path, linkHandling: SKIP_LINKS)` (named arg, skipping the unchanged `$visibility` and `$writeFlags`). Verification ------------ The project has `FlySystemAdapter::createForPath` as its one code path for building filesystem instances from a local path, so this covers every entry point. Downstream reproducer (now green once shipped): ln -s AGENTS.md Documentation/CLAUDE.md docker run --rm -v "$PWD:/project" -w /project \ ghcr.io/typo3-documentation/render-guides:latest \ render --config=Documentation --output=out Documentation Signed-off-by: Sebastian Mendel <github@sebastianmendel.de>
PHPCS flagged the bare `LOCK_EX` reference in the v1 Local adapter constructor call as a fallback global name. Add `use const LOCK_EX` to match the repo's coding standard. Signed-off-by: Sebastian Mendel <github@sebastianmendel.de>
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.
Problem
FlySystemAdapter::createForPath()inpackages/filesystem/src/FlySystemAdapter.phpinstantiates the Local/Flysystem adapter with the default link-handling mode, which isDISALLOW_LINKSin bothleague/flysystemv1 and v3. Any symbolic link encountered duringlistContents()throws and aborts the caller — v1 withNotSupportedException, v3 withSymbolicLinkEncountered.phpDocumentor\Guides\Handlers\ParseDirectoryHandlerusesFlySystemAdapter::listContents()to discover the entrypoint file of an input directory, so a single symlink anywhere in the input tree kills the run, even for symlinks that point to files the parser would otherwise ignore (e.g.CLAUDE.md -> AGENTS.mdfor cross-tool AI instructions, vendored references, build artefacts).Downstream report in the TYPO3 render-guides wrapper: TYPO3-Documentation/render-guides#1234.
Fix
Pass
SKIP_LINKSas the link-handling argument to both the v1 and v3 Local adapters. This preserves the current "do not follow links" posture but turns an abort into a silent skip — matching how most documentation builders treat filesystem entries they can't or shouldn't parse.LOCK_EXis the library's own default for$writeFlagsand has to be restated to reach the$linkHandlingslot.$visibilityand$writeFlags.Rationale
Two paths would have been equivalent from Flysystem's side:
SKIP_LINKS— encounters are silently skipped during listing.DISALLOW_LINKSwith the exception caught at call sites and treated as skip.SKIP_LINKSis the narrower, non-intrusive change: it fixes every caller at once, requires no error-handling adjustments inParseDirectoryHandleror any future consumer, and the semantics ("do not follow symlinks but do not error on them") are what almost all docs builders actually want.If a stricter mode is ever needed,
FlySystemAdapter::createForPathcould grow an optional parameter; default staysSKIP_LINKS.Reproduction
Tests
I didn't add a unit test —
packages/filesystem/tests/unit/currently has no tests forFlySystemAdapter::createForPathand the existing tests exercisePathandFinder\SpecificationFactory. Happy to add one if you point me at the preferred style (tmpdir + symlink + assert no throw); didn't want to invent a pattern.