Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 041a217

Browse filesBrowse files
Paul Schwabaueraduh95
authored andcommitted
fs: fix rmSync error code
Return the correct error code, when a directory_not_empty error occurred. Fixes: #57095 PR-URL: #57103 Reviewed-By: Jason Zhang <xzha4350@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 98d328a commit 041a217
Copy full SHA for 041a217

File tree

Expand file treeCollapse file tree

2 files changed

+14
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-5
lines changed
Open diff view settings
Collapse file

‎src/node_file.cc‎

Copy file name to clipboardExpand all lines: src/node_file.cc
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,8 @@ static void RmSync(const FunctionCallbackInfo<Value>& args) {
17051705
return env->ThrowErrnoException(EPERM, "rm", message.c_str(), path_c_str);
17061706
} else if (error == std::errc::directory_not_empty) {
17071707
std::string message = "Directory not empty: " + file_path_str;
1708-
return env->ThrowErrnoException(EACCES, "rm", message.c_str(), path_c_str);
1708+
return env->ThrowErrnoException(
1709+
ENOTEMPTY, "rm", message.c_str(), path_c_str);
17091710
} else if (error == std::errc::not_a_directory) {
17101711
std::string message = "Not a directory: " + file_path_str;
17111712
return env->ThrowErrnoException(ENOTDIR, "rm", message.c_str(), path_c_str);
Collapse file

‎test/parallel/test-fs-rm.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-rm.js
+12-4Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,20 @@ if (isGitPresent) {
481481
// IBMi has a different access permission mechanism
482482
// This test should not be run as `root`
483483
if (!common.isIBMi && (common.isWindows || process.getuid() !== 0)) {
484-
function makeDirectoryReadOnly(dir, mode) {
484+
function makeDirectoryReadOnly(dir, allowExecute) {
485485
let accessErrorCode = 'EACCES';
486+
if (common.isMacOS && allowExecute) {
487+
accessErrorCode = 'ENOTEMPTY';
488+
}
486489
if (common.isWindows) {
487490
accessErrorCode = 'EPERM';
488-
execSync(`icacls ${dir} /deny "everyone:(OI)(CI)(DE,DC)"`);
491+
const permissions = ['DE', 'DC'];
492+
if (!allowExecute) {
493+
permissions.push('X');
494+
}
495+
execSync(`icacls ${dir} /deny "everyone:(OI)(CI)(${permissions.join(',')})"`);
489496
} else {
497+
const mode = allowExecute ? 0o555 : 0o444;
490498
fs.chmodSync(dir, mode);
491499
}
492500
return accessErrorCode;
@@ -510,7 +518,7 @@ if (isGitPresent) {
510518
try {
511519
fs.mkdirSync(dirname, common.mustNotMutateObjectDeep({ recursive: true }));
512520
fs.writeFileSync(filePath, 'hello');
513-
const code = makeDirectoryReadOnly(dirname, 0o444);
521+
const code = makeDirectoryReadOnly(dirname, false);
514522
assert.throws(() => {
515523
fs.rmSync(filePath, common.mustNotMutateObjectDeep({ force: true }));
516524
}, {
@@ -532,7 +540,7 @@ if (isGitPresent) {
532540
fs.mkdirSync(middle);
533541
fs.mkdirSync(path.join(middle, 'leaf')); // Make `middle` non-empty
534542
try {
535-
const code = makeDirectoryReadOnly(middle, 0o555);
543+
const code = makeDirectoryReadOnly(middle, true);
536544
try {
537545
assert.throws(() => {
538546
fs.rmSync(root, common.mustNotMutateObjectDeep({ recursive: true }));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.