Commit cd665e4
committed
lib: normalize . and .. in path before rm/rmSync
When fs.rm, fs.rmSync, or fs.promises.rm receive a path containing '.'
or '..' components (e.g. 'a/b/../.'), the sync and async implementations
behaved differently:
- rmSync (C++ binding): std::filesystem::remove_all deleted the
directory's children, but when trying to remove the top-level entry
the path became invalid (the '..' referred to a now-deleted directory),
causing the parent directory to be left behind.
- promises.rm / rm (JS rimraf): rmdir(2) on a path ending in '.'
returns EINVAL on POSIX, so the operation failed immediately without
removing anything.
Fix by calling path.normalize() on string paths immediately after
getValidatedPath(), before the path is passed to either rimraf or the
C++ binding. This resolves '.' and '..' lexically (e.g. 'a/b/../.'
becomes 'a'), giving both code paths a clean, unambiguous path to
operate on.
Fixes: #619581 parent 9145cc6 commit cd665e4
3 files changed
+44
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1179 | 1179 | | |
1180 | 1180 | | |
1181 | 1181 | | |
| 1182 | + | |
1182 | 1183 | | |
1183 | 1184 | | |
1184 | 1185 | | |
| |||
1202 | 1203 | | |
1203 | 1204 | | |
1204 | 1205 | | |
| 1206 | + | |
| 1207 | + | |
1205 | 1208 | | |
1206 | | - | |
| 1209 | + | |
1207 | 1210 | | |
1208 | 1211 | | |
1209 | 1212 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
802 | 802 | | |
803 | 803 | | |
804 | 804 | | |
| 805 | + | |
805 | 806 | | |
806 | 807 | | |
807 | 808 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
569 | 569 | | |
570 | 570 | | |
571 | 571 | | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
0 commit comments