Repository navigation
Copy a symbolic link even when its target does not exist - #433
Merged
Merged
Conversation
copyFile(File, File) checked source.exists() before the symbolic-link branch, and File.exists() follows links, so a dangling link was rejected as a missing file. The link branch now runs first and creates the destination directory like the regular-file path does, and the permission copy is skipped for a link destination because the link has no permissions of its own and its target may be absent. Fixes #306
elharo
approved these changes
Sep 11, 2026
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.
copyFile(File, File)checkedsource.exists()before its symbolic-link branch, andFile.exists()follows links, so a link whose target is missing was rejected as a missing file. The link branch now runs first. Two smaller gaps in the same path surfaced while testing: the link branch did not create the destination directory the way the regular-file path does, and the filtering overload then tried to copy POSIX permissions onto a dangling link, which follows the link and fails. Both are handled in this change.The two tests follow the scenarios from #110 by @kwin: a dangling link, and a relative link copied into another directory where its target does not resolve. Both are skipped on Windows like the other symlink tests here.
copyFileis deprecated in favour ofFiles.copywithNOFOLLOW_LINKS, but it still ships, and maven-filtering hit this same path in MSHARED-1112, so the reordered check is worth having.Fixes #306.
Verified:
mvn -B verifyon JDK 17 -> Tests run: 793, Failures: 0, Errors: 0; on master the dangling-link test fails withIOException: File .../dangling does not exist.This change was created with AI assistance.