Skip to content
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

fs: fix rmsync error swallowing #38684

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! fixup! fs: fix rmsync error swallowing
  • Loading branch information
Linkgoron committed May 19, 2021
commit 089fd73ebc40f91c80c914c2ac2ffaa792eff2b1
11 changes: 2 additions & 9 deletions lib/internal/fs/rimraf.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,7 @@ function _rmdirSync(path, options, originalErr) {
if (err.code === 'ENOENT')
return;
if (err.code === 'ENOTDIR') {
if (originalErr) {
throw originalErr;
}
throw err;
throw originalErr || err;
}

if (notEmptyErrorCodes.has(err.code)) {
Expand Down Expand Up @@ -278,11 +275,7 @@ function _rmdirSync(path, options, originalErr) {
}
}

if (originalErr) {
throw originalErr;
} else {
throw err;
}
throw originalErr || err;
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-mkdir-recursive-eaccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function makeDirectoryReadOnly(dir) {
let accessErrorCode = 'EACCES';
if (common.isWindows) {
accessErrorCode = 'EPERM';
execSync(`icacls ${dir} /deny "everyone:(OI)(CI)(D,DC,AD,WD)"`);
execSync(`icacls ${dir} /deny "everyone:(OI)(CI)(DE,DC,AD,WD)"`);
RaisinTen marked this conversation as resolved.
Show resolved Hide resolved
Linkgoron marked this conversation as resolved.
Show resolved Hide resolved
} else {
fs.chmodSync(dir, '444');
}
Expand Down
22 changes: 11 additions & 11 deletions test/parallel/test-fs-rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,22 +287,24 @@ function removeAsync(dir) {
// IBMi has a different access permission mechanism
// This test should not be run as `root`
if (!common.isIBMi && (common.isWindows || process.getuid() !== 0)) {
RaisinTen marked this conversation as resolved.
Show resolved Hide resolved
function makeDirectoryReadOnly(dir) {
function makeDirectoryReadOnly(dir, mode) {
let accessErrorCode = 'EACCES';
if (common.isWindows) {
accessErrorCode = 'EPERM';
execSync(`icacls ${dir} /deny "everyone:(OI)(CI)(D,DC)"`);
execSync(`icacls ${dir} /deny "everyone:(OI)(CI)(DE,DC)"`);
RaisinTen marked this conversation as resolved.
Show resolved Hide resolved
Linkgoron marked this conversation as resolved.
Show resolved Hide resolved
} else {
fs.chmodSync(dir, 0o444);
fs.chmodSync(dir, mode);
}
return accessErrorCode;
}

function makeDirectoryWritable(dir) {
if (common.isWindows) {
execSync(`icacls ${dir} /remove:d "everyone"`);
} else {
fs.chmodSync(dir, 0o777);
if (fs.existsSync(dir)) {
if (common.isWindows) {
execSync(`icacls ${dir} /remove:d "everyone"`);
} else {
fs.chmodSync(dir, 0o777);
}
}
}

Expand All @@ -314,7 +316,7 @@ function removeAsync(dir) {
try {
fs.mkdirSync(dirname, { recursive: true });
fs.writeFileSync(filePath, 'hello');
const code = makeDirectoryReadOnly(dirname);
const code = makeDirectoryReadOnly(dirname, 0o444);
assert.throws(() => {
fs.rmSync(filePath, { force: true });
}, {
Expand All @@ -335,10 +337,8 @@ function removeAsync(dir) {
const middle = path.join(root, 'middle');
fs.mkdirSync(middle);
fs.mkdirSync(path.join(middle, 'leaf')); // Make `middle` non-empty
const mode = common.isWindows ? 0 : 0o555;
const code = common.isWindows ? 'EPERM' : 'EACCES';
try {
fs.chmodSync(middle, mode);
const code = makeDirectoryReadOnly(middle, 0o555);
assert.throws(() => {
fs.rmSync(root, { recursive: true });
}, {
Expand Down