fix: resolve relative symlink targets against parent directory#394
Draft
Koan-Bot wants to merge 1 commit into
Draft
fix: resolve relative symlink targets against parent directory#394Koan-Bot wants to merge 1 commit into
Koan-Bot wants to merge 1 commit into
Conversation
_find_file_or_fh() resolved relative symlink targets (e.g. 'target.txt'
in symlink('target.txt', '/dir/link')) against getcwd() instead of the
directory containing the symlink. This meant that opening a file through
a relative symlink would fail to find the target in most cases.
POSIX mandates that relative symlink targets resolve relative to the
directory containing the symlink. __cwd_abs_path() already handled this
correctly, but the core _find_file_or_fh() resolution path did not.
The fix prepends the symlink's parent directory to relative targets
before recursing, matching POSIX semantics and __cwd_abs_path behavior.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
What
Fix
_find_file_or_fh()to resolve relative symlink targets against the symlink's parent directory instead ofgetcwd().Why
POSIX mandates that relative symlink targets (e.g.,
symlink('target.txt', '/dir/link')) resolve relative to the directory containing the symlink. The__cwd_abs_path()function already handled this correctly, but the core path resolution in_find_file_or_fh()passed relative targets directly to_abs_path_to_file(), which resolves againstgetcwd(). This meant opening a file through a relative symlink silently resolved to the wrong path.How
Before recursing on a symlink target, check if it's relative. If so, prepend the directory portion of the symlink's absolute path. This is the same approach
__cwd_abs_path()uses (tracking$resolved), applied to the simpler recursive resolver.Testing
t/relative_symlink.twith 7 subtests: simple relative,../paths, chained relative symlinks, stat follow, broken relative symlink, write-through, and unlink behavior.symlink.t,symlink_follow_ops.t,symlink_link.t,cwd_abs_path.t).🤖 Generated with Claude Code
Quality Report
Changes: 3 files changed, 112 insertions(+), 1 deletion(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline