@@ -481,12 +481,20 @@ if (isGitPresent) {
481
481
// IBMi has a different access permission mechanism
482
482
// This test should not be run as `root`
483
483
if ( ! common . isIBMi && ( common . isWindows || process . getuid ( ) !== 0 ) ) {
484
- function makeDirectoryReadOnly ( dir , mode ) {
484
+ function makeDirectoryReadOnly ( dir , allowExecute ) {
485
485
let accessErrorCode = 'EACCES' ;
486
+ if ( common . isMacOS && allowExecute ) {
487
+ accessErrorCode = 'ENOTEMPTY' ;
488
+ }
486
489
if ( common . isWindows ) {
487
490
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 ( ',' ) } )"` ) ;
489
496
} else {
497
+ const mode = allowExecute ? 0o555 : 0o444 ;
490
498
fs . chmodSync ( dir , mode ) ;
491
499
}
492
500
return accessErrorCode ;
@@ -510,7 +518,7 @@ if (isGitPresent) {
510
518
try {
511
519
fs . mkdirSync ( dirname , common . mustNotMutateObjectDeep ( { recursive : true } ) ) ;
512
520
fs . writeFileSync ( filePath , 'hello' ) ;
513
- const code = makeDirectoryReadOnly ( dirname , 0o444 ) ;
521
+ const code = makeDirectoryReadOnly ( dirname , false ) ;
514
522
assert . throws ( ( ) => {
515
523
fs . rmSync ( filePath , common . mustNotMutateObjectDeep ( { force : true } ) ) ;
516
524
} , {
@@ -532,7 +540,7 @@ if (isGitPresent) {
532
540
fs . mkdirSync ( middle ) ;
533
541
fs . mkdirSync ( path . join ( middle , 'leaf' ) ) ; // Make `middle` non-empty
534
542
try {
535
- const code = makeDirectoryReadOnly ( middle , 0o555 ) ;
543
+ const code = makeDirectoryReadOnly ( middle , true ) ;
536
544
try {
537
545
assert . throws ( ( ) => {
538
546
fs . rmSync ( root , common . mustNotMutateObjectDeep ( { recursive : true } ) ) ;
0 commit comments