Skip to content

requireFilesExist should accept a symbolic link - #1031

Merged
slawekjaranowski merged 1 commit into
apache:masterfrom
slawekjaranowski:require-files-exist-symlink
Sep 29, 2026
Merged

slawekjaranowski merged 1 commit into
apache:masterfrom
slawekjaranowski:require-files-exist-symlink

Conversation

@slawekjaranowski

Copy link
Copy Markdown
Member

Fixes #501

requireFilesExist reports an existing symbolic link as missing. The case check
added for #477 compares the configured file name with the one from
getCanonicalFile(), which resolves a link to its target, so a link whose name
differs from its target name β€” the normal case β€” never matches.

The .. and . part of #501 was already fixed in #1011; this covers the
remaining symbolic link part.

How

toRealPath(NOFOLLOW_LINKS) replaces getCanonicalFile(). It still corrects the
case on a case-insensitive filesystem and still collapses .. and ., but
leaves the link itself alone:

getCanonicalFile() toRealPath(NOFOLLOW_LINKS)
symbolic link ❌ reported missing βœ… found
POM.xml vs pom.xml βœ… rejected βœ… rejected
path through .. βœ… found βœ… found

The check moves to AbstractRequireFiles behind a shared fileExists(File), so
requireFilesExist, requireFilesDontExist and requireFilesSize share one
notion of an existing file.

Behavioural change

On a case-insensitive filesystem (Windows, default macOS) a file whose name
differs only in case is now consistently treated as a different file:

  • requireFilesDontExist no longer fails on it
  • requireFilesSize reports it as missing instead of measuring a different file

On a case-sensitive filesystem nothing changes. The three rule pages document
this.

Credit

The symbolic link tests and the relative path IT come from #297 by @roadSurfer.
That PR proposed reverting #477 entirely; this keeps the case check and fixes
the link handling instead, so #297 can be closed.

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
  • Run mvn verify to make sure basic checks pass.
  • You have run the integration tests successfully (mvn -Prun-its verify).
  • I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004

The case check added for apache#477 compares the configured file name with the
one from getCanonicalFile(), which resolves a symbolic link to its
target. A link whose name differs from its target name - the normal case
- was therefore reported as missing.

Keep getCanonicalFile() for a regular file, where nothing is resolved
away, and look the name up among the entries of the parent directory
when the path is a symbolic link. A directory entry carries the name as
it is stored on disk. toRealPath(NOFOLLOW_LINKS) would be cheaper but is
not an option: it corrects the case only since JDK 21, so on an older
JDK the check would silently pass for any name.

Move the check to AbstractRequireFiles behind a shared fileExists(File),
so that all three rules share one notion of an existing file. This
changes behaviour on a case-insensitive filesystem: requireFilesDontExist
no longer fails on a file whose name differs only in case, and
requireFilesSize reports such a file as missing instead of measuring a
different file. Document the case handling on the three rule pages.

The symbolic link tests and the relative path IT come from apache#297. The
try/catch blocks in the touched test classes are converted to
assertThrows along the way.

Fixes apache#501

Co-authored-by: Jason Irwin <jason.irwin@idoxgroup.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@slawekjaranowski
slawekjaranowski merged commit e30b94b into apache:master Sep 29, 2026
17 checks passed
@slawekjaranowski
slawekjaranowski deleted the require-files-exist-symlink branch September 29, 2026 06:56
@github-actions github-actions Bot added this to the 3.6.4 milestone Sep 29, 2026
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.

[MENFORCER-390] "requireFilesExist" no longer handles non-canonical paths

2 participants