gnodet opened a new pull request, #401:
URL: https://github.com/apache/maven-filtering/pull/401
## Problem
Issue #248 (MSHARED-1004) reports two bugs with symbolic links as resources:
**Bug 1 — file symlink copied verbatim (inconsistency with dir symlinks)**
A previous NIO-based rewrite of `copyFile` (commit 7e0adf59, MSHARED-966)
used `Files.copy(from, to, NOFOLLOW_LINKS)`, which copies a symlink-to-file
verbatim into the target directory. The relative link target then points to the
wrong location. This was later reverted; the current code using
`Files.copy(from, outputStream)` follows source symlinks naturally — so Bug 1
is already fixed in `master`.
**Bug 2 — failure on second `mvn compile`**
- With the old `NOFOLLOW_LINKS` code: second run throws
`FileAlreadyExistsException` because `to` already exists as a symlink and no
`REPLACE_EXISTING` was passed.
- With the current code: if a dangling symlink is left at the destination
(e.g. from a previous build with the old code, or an incremental-build
scenario), `CachingOutputStream` / `CachingWriter` follow the link and fail
with `NoSuchFileException` because the link target doesn't exist in the target
directory.
## Fix
In `FilteringUtils.copyFile`, before opening the destination for writing,
detect whether `to` is a symbolic link and delete it. This ensures the output
is always a regular file, regardless of what existed at that path before.
```java
if (Files.isSymbolicLink(to)) {
Files.delete(to);
}
```
## Tests added
Three new tests in `FilteringUtilsTest` (unit) and two in
`DefaultMavenFileFilterTest` (integration):
| Test | What it checks |
|------|---------------|
| `copyFileSymlinkIsFollowedAndWrittenAsRegularFile` | Source symlink →
regular file in output |
| `copyFileReplacesDanglingSymlinkAtDestination` | Dangling symlink at dest
replaced, no exception (no-filter path) |
| `copyFileWithFilteringReplacesDanglingSymlinkAtDestination` | Same, with
filter wrappers active |
| `copyFileSymlinkSourceIsFollowed` (integration) | Two consecutive copies
via `MavenFileFilter` both succeed |
| `copyFileReplacesDanglingSymlinkAtDestination` (integration) | Via
`MavenFileFilter`, dangling symlink replaced |
Fixes #248
--
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]