fix: propagate writes across hard links sharing the same inode#385
Draft
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
fix: propagate writes across hard links sharing the same inode#385toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
Conversation
link() copied contents as an independent scalar, so writing to one hard link was invisible through the other — violating POSIX semantics where hard links share the same underlying data. Add _sync_hardlink_contents() that propagates contents changes to all mocks sharing the same inode. Called from FileHandle _write_bytes(), the contents() setter, and __open truncation path. 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
Hard link writes now propagate to all mocks sharing the same inode.
Why
link()copied contents as an independent scalar, so writing through onehard link was invisible when reading through the other — violating POSIX
semantics where hard links share the same underlying data block.
How
Added
_sync_hardlink_contents()that iterates same-inode mocks (samepattern as the existing nlink propagation in
unlink()) and syncs thecontents scalar. Called from three write paths:
FileHandle::_write_bytes()— after print/syswritecontents()setter — coverstruncate()and programmatic updates__opentruncation — the>/+>mode path that bypasses the setterThe sync is guarded by
nlink > 1so non-linked files pay zero cost.Testing
7 new test cases in
t/symlink_link.t:open('>')propagationtruncate()propagationFull suite: 1594 tests pass (pre-existing
fh-ref-leak.tfailure excluded).