◐ Shell
clean mode source ↗

fs: fix rmSync error code · nodejs/node@041a217

@@ -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 }));