vfs: fix rename over non-empty directory - #65613
Open
christianaurichzm wants to merge 1 commit into
Open
Conversation
The memory provider only rejected renames whose destination had a different type than the source, so renaming a directory onto another directory silently dropped the destination and everything under it. An existing destination directory has to be empty; rename(2) reports ENOTEMPTY otherwise, and RealFSProvider already does so because it delegates to fs.renameSync(). Also, decrement nlink on a file that is replaced by a rename, and make a rename whose two names resolve to the same entry a no-op, which covers renaming one hard link onto another. Signed-off-by: Christian Aurich <christian.aurichzm@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #65613 +/- ##
==========================================
- Coverage 90.07% 90.07% -0.01%
==========================================
Files 751 751
Lines 254875 254928 +53
Branches 48108 48126 +18
==========================================
+ Hits 229579 229624 +45
- Misses 16466 16484 +18
+ Partials 8830 8820 -10
🚀 New features to boost your workflow:
|
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.
MemoryProvider#renameSync()only rejected a destination whose type differed from the source (EISDIR/ENOTDIR). When both sides were directories it fell through to replacing the destination in its parent, so the destination directory and everything under it disappeared:rename(2) accepts an existing directory as the destination only when it is empty, and fails with ENOTEMPTY otherwise. RealFSProvider delegates to fs.renameSync() and already behaves that way, so the two providers backing the same node:vfs API disagreed.
Two smaller fixes in the same function, both covered by the new tests: