Skip to content

Follow symbolic links to files when isFollowingSymLinks() is set - #187

Merged
slachiewicz merged 1 commit into
masterfrom
follow-symlinks-to-files
Aug 19, 2026
Merged

slachiewicz merged 1 commit into
masterfrom
follow-symlinks-to-files

Conversation

@slachiewicz

@slachiewicz slachiewicz commented Aug 19, 2026 •

Copy link
Copy Markdown
Member

Supersedes #38, which cannot be rebased: it targets the master branch of a fork, its author stepped away in 2021, and half its diff (a FileAttributes(Path, …) constructor) has since landed as FileAttributes(Path, boolean followLinks). Authorship is preserved with a Co-authored-by trailer.

What is left of that PR is one line. getResources() already passes the flag to DirectoryScanner.setFollowSymlinks(), so symlinked directories are descended, but addResources() read every entry's attributes with NOFOLLOW_LINKS. Since ResourceFactory.createResource() branches on isSymbolicLink(), a symlinked file always became a PlexusIoSymlinkResource — the flag had no effect on files.

#38 resolved the entry with toRealPath(); reading the attributes with follow instead is enough, and it leaves the entry name alone. That also answers @plamentotev's review point on the original PR without a getCanonicalPath() round trip.

The flag defaults to true, so this does change what direct plexus-io consumers get. plexus-archiver is not among them: AbstractArchiver hardcodes setFollowingSymLinks(false) for its file sets, so archiver and every Maven plugin above it are untouched. Worth a release note either way, and the draft release is already a minor bump.

toRealPath() and follow-attributes both throw NoSuchFileException on a dangling link. DirectoryScanner with followSymlinks=true never surfaces one, so no handling is needed — danglingSymlinkDoesNotBreakCollection pins that down rather than leaving it to inference.

This does not close codehaus-plexus/plexus-archiver#160. It is the first of three steps: plexus-archiver must stop hardcoding false and expose the choice per FileSet (@michael-o asked for both retention and resolution), and maven-archiver must carry the setting through to maven-source-plugin and friends.

Verified: mvn clean verify → 58 tests, green. plexus-archiver's suite against this snapshot → 340 tests, 0 failures.

Fixes #37

This change was created with AI assistance.

The scanner already honours the flag when descending symlinked
directories, but attributes for each entry were always read with
NOFOLLOW_LINKS. ResourceFactory branches on isSymbolicLink(), so every
symlinked file became a PlexusIoSymlinkResource regardless of the flag,
and archives got a dangling link instead of the target's content.

plexus-archiver is unaffected: AbstractArchiver hardcodes
setFollowingSymLinks(false) for its file sets.

Fixes #37

Co-authored-by: mirabilos <t.glaser@tarent.de>
@slachiewicz slachiewicz added the bug Something isn't working label Aug 19, 2026
@slachiewicz
slachiewicz requested a lite review from Copilot August 19, 2026 15:46

This comment was marked as resolved.

@slachiewicz
slachiewicz merged commit f2387ba into master Aug 19, 2026
15 checks passed
@slachiewicz
slachiewicz deleted the follow-symlinks-to-files branch August 19, 2026 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support following symbolic links to *files* as well Symbolic links are added as symlinks to the sources JAR instead of being followed

2 participants