fix: update parent directory nlink on mkdir/rmdir/rename#374
Draft
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
fix: update parent directory nlink on mkdir/rmdir/rename#374toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
Conversation
POSIX mandates that a directory's nlink reflects the count of its subdirectories (each subdirectory's ".." entry is a hard link back to the parent). Previously, mkdir() and rmdir() did not update the parent directory's nlink, and rename() of a directory between parents also left both parents' nlink unchanged. Now: - mkdir increments parent dir nlink by 1 - rmdir decrements parent dir nlink by 1 (floored at 2) - rename of a directory across parents decrements old parent, increments new 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
Maintain accurate
nlinkon parent directories when subdirectories are created, removed, or renamed across parents.Why
POSIX mandates that a directory's
nlinkequals 2 + number of immediate subdirectories (each child's..entry is a hard link to the parent). MockFile was not updating parentnlinkonmkdir(),rmdir(), or cross-parentrename(), causing(stat $dir)[3]to return stale values. Code that relies onnlinkto detect subdirectory presence (e.g.,findoptimizations,File::Find) would see incorrect results.How
__mkdir: increment parent dir's nlink after creating the subdirectory__rmdir: decrement parent dir's nlink after removing the subdirectory (floored at 2)__rename: when a directory moves between parents, decrement old parent and increment new parent; same-parent rename is a no-op for nlinkTesting
New
t/parent_nlink.twith 8 subtests covering: single/multiple mkdir, rmdir, floor guard, file unlink (no effect), cross-parent rename, same-parent rename, file rename (no effect). Full test suite passes (only pre-existingfh-ref-leak.tfailure).🤖 Generated with Claude Code