fix: lstat on unlinked symlink returns ENOENT#248
Merged
atoomic merged 1 commit intocpanel:masterfrom Feb 28, 2026
Merged
Conversation
_mock_stat used `!$file_data->is_link && !defined $file_data->contents()` to detect non-existent mocks. This excluded ALL symlinks — even deleted ones (readlink=undef after unlink). After unlink, lstat would still return a valid stat array instead of failing. Replace with `!$file_data->exists()` which correctly handles all three types: files (contents=undef), dirs (has_content=0), and unlinked symlinks (readlink=undef). Co-Authored-By: Claude Opus 4.6 <[email protected]>
atoomic
approved these changes
Feb 28, 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.
What
lstat()on an unlinked symlink now correctly returns ENOENT instead of stale stat data.Why
After
unlink($symlink),_mock_statwas skipping the "file not present" check for symlinks because the condition!$file_data->is_linkexcluded them. An unlinked symlink still hasis_link()true (it's still a symlink object), butexists()is false — which is the correct predicate.How
Replaced
!$file_data->is_link && !defined $file_data->contents()with the canonical!$file_data->exists()check, which handles files, dirs, and symlinks uniformly.Testing
Added 5 tests in
t/symlink.tcovering lstat/stat behavior before and after symlink unlink.🤖 Generated with Claude Code