Discrepancy between `fs.rmSync` and `fs/promises.rm` behavior with `.` and `..` in paths
まだ誰も着手していません。
- 主要言語
- JavaScript
- スター
- 122k
- フォーク
- 37.3k
- 平均マージ
- 4日 2時間
- マージ済み PR(30日)
- 283
説明
Version
v25.6.1
Platform
Darwin moxy.lan 25.3.0 Darwin Kernel Version 25.3.0: Wed Jan 28 20:47:03 PST 2026; root:xnu-12377.81.4~5/RELEASE_ARM64_T6031 arm64
Subsystem
lib/internal/fs/rimraf.js
What steps will reproduce the bug?
Create a nested folder:
mkdir -p a/b/c/d
Attempt to delete with this weirdly constructed path:
Welcome to Node.js v25.6.1.
Type ".help" for more information.
> await require('fs/promises').rm('a/b/../.', { recursive: true, force: true })
Uncaught [Error: EINVAL: invalid argument, rmdir 'a/b/../.'] {
errno: -22,
code: 'EINVAL',
syscall: 'rmdir',
path: 'a/b/../.'
}
Verify that nothing was removed:
$ tree
./
└── a/
└── b/
└── c/
└── d/
Attempt to delete synchronously:
> require('fs').rmSync('a/b/../.', { recursive: true, force: true })
undefined
It was (mostly?) removed:
$ tree
./
└── a/
The weird thing is that a/b/../. should resolve to just a, so it's weird that it only deletes up to b. It's almost as if the rmSync method is coalescing /../. into just /.
Also, if the . is not the last item, then it seems to be fine? a/b/.././b deletes the b folder, and a/b/.. deletes just b, but not a.
At least, it seems like the sync and asynchronous methods should either both fail, or both succeed, with the same error.
How often does it reproduce? Is there a required condition?
every time, see repro steps above
What is the expected behavior? Why is that the expected behavior?
sync and asynchronous rm methods should fail and succeed in the same way on the same input.
What do you see instead?
Some cases where rmSync succeeds, and fs/promises.rm fails.
Additional information
I have a fix that I could land in the upstream rimraf library, and I'd of course be happy to send a PR to node to bring it back into alignment, since there have also been some improvements in performance and Windows reliability.
But it'd be good to know what the intended behavior is, so that the errors can be made consistent with Node's intended design first.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
lib/internal/fs/rimraf.js から始め、報告された a/b/../. の再現を fs/promises.rm と fs.rmSync の両方で実行します。各パスがどのように処理されるかを比較し、周辺のファイルシステムテストを確認する前に、意図された一貫した動作を判断します。完了条件は、これらのドットパスのケースで2つのAPIの動作が一致し、回帰テストのカバレッジによってその動作が保護されることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, nodejs
- 領域
- backend, operating-systems
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 活発
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 55/100