Skip to content

src,test: handle EROFS in mkdir recursive#62725

Open
kennyhyun wants to merge 2 commits intonodejs:mainfrom
kennyhyun:fix/mkdirp-EROFS
Open

src,test: handle EROFS in mkdir recursive#62725
kennyhyun wants to merge 2 commits intonodejs:mainfrom
kennyhyun:fix/mkdirp-EROFS

Conversation

@kennyhyun
Copy link
Copy Markdown

mkdirSync and mkdirpAsync with { recursive: true } incorrectly
convert EROFS (read-only filesystem) to ENOENT when the underlying
mkdir syscall fails. This causes misleading errors when operating on
read-only filesystems.

This PR adds UV_EROFS to the list of errors that are returned
immediately in MKDirpSync and MKDirpAsync, preventing the incorrect
conversion.

Two test cases are included:

  • A mock-based test using internalBinding to simulate EROFS without
    requiring elevated privileges.
  • An optional integration test that mounts a real read-only tmpfs on
    Linux when passwordless sudo is available.

Fixes: #47098
Refs: #48105
Co-authored-by: Alberto Moretti moretti919@gmail.com

kennyhyun and others added 2 commits April 12, 2026 17:51
mkdirSync with { recursive: true } on a read-only filesystem
incorrectly throws ENOENT instead of the expected EROFS error.

Two test cases are included:
- On Linux with passwordless sudo, mounts a real read-only tmpfs to
  verify the error code against the actual kernel behavior.
- Uses internalBinding to mock binding.mkdir and simulate EROFS,
  ensuring the error propagates correctly without requiring root.

Refs: nodejs#47098
Refs: nodejs#48105
Signed-off-by: Kenny Yeo <kenny@yeoyou.net>
Add UV_EROFS to the list of errors that should be returned
immediately in MKDirpSync and MKDirpAsync, preventing it from
being incorrectly converted to ENOENT when mkdir is called with
the recursive option on a read-only filesystem.

Based on the original fix by Alberto Moretti (@hiimjako) in nodejs#48105.

Refs: nodejs#47098
Refs: nodejs#48105
Co-authored-by: Alberto Moretti <moretti919@gmail.com>
Signed-off-by: Kenny Yeo <kenny@yeoyou.net>
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. labels Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mkdir with the recursive flag hides EROFS readonly file system errors with ENOENT

2 participants