Skip to content

fs: report EROFS from recursive mkdir() - #67500

Open
yohannesjoya wants to merge 1 commit into
nodejs:mainfrom
yohannesjoya:fs-mkdirp-erofs
Open

yohannesjoya wants to merge 1 commit into
nodejs:mainfrom
yohannesjoya:fs-mkdirp-erofs

Conversation

@yohannesjoya

Copy link
Copy Markdown
Contributor

fs.mkdir() with recursive: true on a read-only file system reports ENOENT. EROFS isn't in the list of errors MKDirpSync/MKDirpAsync return directly, so it falls into the default branch, which stats the missing path and reports that ENOENT instead. Reproduced on main with fs.mkdirSync('/snap/core/current/x/y', { recursive: true }) on Ubuntu (EROFS without recursive, ENOENT with it).

This adds EROFS next to EACCES, ENOSPC, ENOTDIR and EPERM in both switches. The change is the one @hiimjako proposed in #48105 (carried with Co-authored-by); that PR and @kennyhyun's #62725 stalled because their tests needed sudo mount. The test here uses a read-only file system that is already mounted — on Linux any ro entry in /proc/self/mounts (e.g. /sys in a container), on macOS the system volume — verified with a plain mkdir that must fail with EROFS, and skips if none is available. It fails on main with ENOENT and passes with the fix.

Fixes: #47098
Refs: #48105
Refs: #62725

AI disclosure: I used a coding agent to help search the issue history and draft the test. I reproduced the bug on main, reviewed the change line by line, and ran the fs tests locally.

A recursive mkdir() that hits a read-only file system treated EROFS like
any unknown error: it stat()ed the missing path and reported the ENOENT
from that instead. Return EROFS straight away, as mkdir() already does
for EACCES, ENOSPC, ENOTDIR and EPERM.

The test uses a read-only file system that is already mounted (listed
in /proc/self/mounts on Linux, the system volume on macOS) and skips
when there is none, since mounting one needs root.

Fixes: nodejs#47098
Refs: nodejs#48105
Refs: nodejs#62725
Co-authored-by: Alberto Moretti <moretti919@gmail.com>
Signed-off-by: Yohannes Desta <yohannesdestagebru10@gmail.com>
@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 file-system APIs and the fs module. needs-ci PRs that need a full CI run. labels Nov 15, 2026
@codecov

codecov Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.67%. Comparing base (c99ebf2) to head (1bfe69d).
⚠️ Report is 163 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67500      +/-   ##
==========================================
- Coverage   92.99%   90.67%   -2.32%     
==========================================
  Files         428      799     +371     
  Lines      195633   280243   +84610     
  Branches    30281    54119   +23838     
==========================================
+ Hits       181937   254123   +72186     
- Misses      13369    16241    +2872     
- Partials      327     9879    +9552     
Files with missing lines Coverage Δ
src/node_file.cc 75.97% <ø> (ø)

... and 554 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jasnell jasnell added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 16, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 16, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

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 file-system APIs and the fs module. 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

3 participants