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 256408 +13
Branches 48499 48503 +4
==========================================
+ Hits 230937 230942 +5
Misses 16569 16569
- 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! |
MemoryProvider#renameSync() read children.size on the destination directory without populating it first. A lazy directory keeps its entries in a populate callback until something reads them, so a lazy destination looked empty, passed the ENOTEMPTY check and was replaced along with everything it would have contained. #lookupEntry() populates only the directories it walks through, never the final entry, so the destination has to be populated explicitly. The regression test lives in test-vfs-memory-provider-dynamic.js because lazy directories have no public construction API and that file already builds the entries by hand; the directory scaffolding there is now shared through a makeDirEntry() helper.
This comment was marked as outdated.
This comment was marked as outdated.
|
Looks like |
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> PR-URL: #65613 Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
|
Landed in b53ddc0 |
|
Landed manually as the CI failures were flaky tests, and there was no "Resume Build" button. |
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: