Commit 9e032a9
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 9e032a9
3 files changed
+44
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1179 | 1179 | | |
1180 | 1180 | | |
1181 | 1181 | | |
| 1182 | + | |
| 1183 | + | |
1182 | 1184 | | |
1183 | 1185 | | |
1184 | 1186 | | |
| |||
1202 | 1204 | | |
1203 | 1205 | | |
1204 | 1206 | | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
1205 | 1210 | | |
1206 | | - | |
| 1211 | + | |
1207 | 1212 | | |
1208 | 1213 | | |
1209 | 1214 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
802 | 803 | | |
803 | 804 | | |
804 | 805 | | |
| 806 | + | |
| 807 | + | |
805 | 808 | | |
806 | 809 | | |
807 | 810 | | |
| |||
| 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 | + | |
0 commit comments