-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
fs: recursion should bail on permission error #31505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4ca2f90
fs: recursion should bail on permission error
55cd7f4
chore: address code review
0e1be3c
chore: debugging Windows issue
47ba6b4
chore: fix up logic to capture error
6e4ae17
chore: make test work on Windows
a103161
chore: refactor windows perms logic
903be10
chore: fix bug with makeDirectoryWritable
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
fs: recursion should bail on permission error
When creating directories recursively, the logic should bail immediately on UV_EACCES and bubble the error to the user. Fixes: #31481
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| 'use strict'; | ||
|
|
||
| // Test that mkdir with recursive option returns appropriate error | ||
| // when executed on folder it does not have permission to access. | ||
| // Ref: https://github.com/nodejs/node/issues/31481 | ||
|
|
||
| const common = require('../common'); | ||
|
|
||
| if (!common.isWindows && process.getuid() === 0) | ||
| common.skip('as this test should not be run as `root`'); | ||
|
|
||
| if (common.isIBMi) | ||
| common.skip('IBMi has a different access permission mechanism'); | ||
|
|
||
| const tmpdir = require('../common/tmpdir'); | ||
| tmpdir.refresh(); | ||
|
|
||
| const assert = require('assert'); | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| let n = 0; | ||
|
|
||
| // Synchronous API should return an EACCESS error with path populated. | ||
| { | ||
| const dir = path.join(tmpdir.path, `mkdirp_${n++}`); | ||
| fs.mkdirSync(dir); | ||
| fs.chmodSync(dir, '444'); | ||
| let err = null; | ||
| try { | ||
| fs.mkdirSync(path.join(dir, '/foo'), { recursive: true }); | ||
| } catch (_err) { | ||
| err = _err; | ||
| } | ||
| assert(err); | ||
| assert.strictEqual(err.code, 'EACCES'); | ||
| assert(err.path); | ||
| } | ||
|
|
||
| // Asynchronous API should return an EACCESS error with path populated. | ||
| { | ||
| const dir = path.join(tmpdir.path, `mkdirp_${n++}`); | ||
| fs.mkdirSync(dir); | ||
| fs.chmodSync(dir, '444'); | ||
| fs.mkdir(path.join(dir, '/bar'), { recursive: true }, (err) => { | ||
| assert(err); | ||
| assert.strictEqual(err.code, 'EACCES'); | ||
| assert(err.path); | ||
| }); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.