Repository navigation
fix(index): make rename onto the same inode a no-op - #31
Merged
Merged
Conversation
Rename(p, "x", p, "x") treated the source as its own replaced destination: it dropped nlink to zero and freed the inode, then re-added a directory entry pointing at it, leaving a dangling entry (nil inode on the next access). The same happened for two hard links to one file. POSIX specifies a no-op. Index.Rename now returns early when the destination entry is the source inode. JournaledIndex.Rename records nothing in that case; it would otherwise emit a DeleteInode that makes journal replay delete the file. Co-authored-by: openhands <openhands@all-hands.dev>
tofarr
marked this pull request as ready for review
December 3, 2026 13:29
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.
Why
Index.Renameassumed that an existing destination entry was always a different file to replace. When the destination was the same inode as the source, it lowered the link count to zero and deleted the inode. This happened forrename("x", "x")and for two hard links to one file. It then added a directory entry that pointed at the deleted inode. The next operation on that entry hit a nil inode and crashed.POSIX says these renames do nothing.
Index.Renamenow returns early when the destination entry is the source inode, and both names stay. The journal wrapper had the same problem. It treated the file as a replaced destination and recorded aDeleteInodeop, so replaying the journal would delete the file.JournaledIndex.Renamenow records nothing in this case.Validation
This PR was drafted by an AI agent on behalf of the user.
@tofarr can click here to continue refining the PR