Skip to content

Fix file creation through dangling symbolic links - #532

Open
YuqiGuo105 wants to merge 1 commit into
google:masterfrom
YuqiGuo105:fix/issue-254-dangling-symlink
Open

YuqiGuo105 wants to merge 1 commit into
google:masterfrom
YuqiGuo105:fix/issue-254-dangling-symlink

Conversation

@YuqiGuo105

Copy link
Copy Markdown

Fixes #254.

Summary

Allow creating a regular file through a symbolic link whose target does not yet exist, without replacing the link.

The initial read-locked lookup already follows symbolic links, but the creation path unconditionally looked up the link with NOFOLLOW_LINKS and rejected it as "not a regular file". The current path resolver can already represent a missing target as a DirectoryEntry; no resolver changes are needed.

Changes

  • Pass the appropriate link-following options into the write-locked creation lookup.
  • Create the file using the resolved entry's parent and name, rather than the original link's name.
  • Preserve CREATE_NEW, explicit NOFOLLOW_LINKS, directory creation and symbolic-link creation semantics.
  • Add 11 public-API regression and compatibility tests covering relative/absolute targets, link chains, stream/channel APIs, initial permissions, missing parents and Windows cross-root targets.

No public API changes. Open-PR searches for the issue number and related keywords found no competing fix before submission.

Validation

macOS arm64, Temurin JDK 25.0.3, Maven 3.9.16; the project retains its Java 8 source/target configuration.

Before the production fix, the new Unix tests reported 10 tests, 5 errors, and the Windows test reported 1 test, 1 error, all six errors being FileSystemException: ... not a regular file:

mvn -B '-Dtest=JimfsUnixLikeFileSystemTest#*danglingSymbolicLink*' -Dsurefire.failIfNoSpecifiedTests=false test
mvn -B '-Dtest=JimfsWindowsLikeFileSystemTest#*danglingSymbolicLink*' -Dsurefire.failIfNoSpecifiedTests=false test

After the fix, all 11 targeted tests passed. Full verification was rerun before submission:

mvn -B clean verify

BUILD SUCCESS — 5,917 tests, 0 failures, 0 errors, 1 existing skipped test (JimfsFileChannelTest.testCloseByInterrupt). Packaging and Javadoc generation completed. Google Java Format 1.35.0 checks on the changed regions and git diff --check also passed.

AI assistance: OpenAI Codex assisted with implementation and local validation.

@google-cla

google-cla Bot commented Nov 4, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Respect link-following options when creating a regular file, and use
the resolved directory-entry name for the new target. Preserve CREATE_NEW,
NOFOLLOW_LINKS and directory/link creation behavior.

Add regression coverage for relative and absolute targets, link chains,
initial attributes, stream/channel APIs and Windows roots.

Fixes google#254

Assisted-by: OpenAI Codex
Signed-off-by: YuqiGuo105 <131561736+YuqiGuo105@users.noreply.github.com>
@YuqiGuo105
YuqiGuo105 force-pushed the fix/issue-254-dangling-symlink branch from 6d6853c to ee2644b Compare November 4, 2026 07:50

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Files.newOutputStream throws if file is a symlink to a non-existing target.

1 participant