vfs: fix rename over non-empty directory - #65613
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #65613 +/- ##
==========================================
- Coverage 90.07% 90.06% -0.01%
==========================================
Files 754 754
Lines 256395 256407 +12
Branches 48499 48501 +2
==========================================
- Hits 230937 230927 -10
- Misses 16569 16583 +14
- Partials 8889 8897 +8
🚀 New features to boost your workflow:
|
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>
e9333ce to
5eeb333
Compare
|
@mcollina, since you just landed the VFS module-loader integration in 4d9cb71, would you mind taking a look at this I rebased it onto the current Thanks! |
| throw createENOTDIR('rename', newPath); | ||
| } | ||
| if (existingDest.isDirectory()) { | ||
| // Cannot overwrite a non-empty directory |
There was a problem hiding this comment.
Populate the destination before inspecting children.size; otherwise a lazy directory with deferred entries appears empty and is overwritten.
| // Cannot overwrite a non-empty directory | |
| this.#ensurePopulated(existingDest, normalizedNew); | |
| // Cannot overwrite a non-empty directory |
A regression test can rename /src over the existing lazy /lazy directory, asserts ENOTEMPTY and that /src remains, then verifies /lazy still contains its deferred entries.
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: