Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fs: fix rmsync error swallowing
Browse files Browse the repository at this point in the history
  • Loading branch information
Linkgoron committed May 16, 2021
1 parent 7448ad0 commit d515441
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions test/parallel/test-fs-rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,22 +284,23 @@ 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)) {
function makeDirectoryReadOnly(dir) {
let accessErrorCode = 'EACCES';
if (common.isWindows) {
accessErrorCode = 'EPERM';
execSync(`icacls ${dir} /inheritance:r`);
execSync(`icacls ${dir} /deny "everyone":W`);
execSync(`icacls ${dir} /deny "everyone:(OI)(CI)(DE,DC)"`);
} else {
fs.chmodSync(dir, '444');
fs.chmodSync(dir, 0o444);
}
return accessErrorCode;
}

function makeDirectoryWritable(dir) {
if (common.isWindows) {
execSync(`icacls ${dir} /grant "everyone":W`);
execSync(`icacls ${dir} /remove:d "everyone"`);
} else {
fs.chmodSync(dirname, 0o777);
}
Expand All @@ -311,11 +312,11 @@ function removeAsync(dir) {
try {
fs.mkdirSync(dirname, { recursive: true });
fs.writeFileSync(filePath, 'hello');
const errorCode = makeDirectoryReadOnly(dirname);
const code = makeDirectoryReadOnly(dirname);
assert.throws(() => {
fs.rmSync(filePath, { force: true });
}, {
code: errorCode,
code,
name: 'Error',
});
} finally {
Expand Down

0 comments on commit d515441

Please sign in to comment.