@@ -5,6 +5,7 @@ const calcDepFlags = require('../lib/calc-dep-flags.js')
55const fs = require ( 'fs' )
66const Arborist = require ( '../lib/arborist/index.js' )
77const rimraf = require ( 'rimraf' )
8+ const { execSync } = require ( 'child_process' )
89
910const t = require ( 'tap' )
1011
@@ -1601,13 +1602,30 @@ t.test('setting lockfileVersion from the file contents', async t => {
16011602 t . test ( 'load should return error correctly when it cant access folder' , async t => {
16021603 const dir = t . testdir ( { } )
16031604 try {
1604- fs . chmodSync ( dir , '000' )
1605+ const err = removePermissions ( dir )
16051606 const res = await Shrinkwrap . load ( { path : dir } )
16061607 t . ok ( res . loadingError , 'loading error should exist' )
1607- t . strictSame ( res . loadingError . errno , - 13 )
1608- t . strictSame ( res . loadingError . code , 'EACCES' )
1608+ t . strictSame ( res . loadingError . code , err )
16091609 } finally {
1610- fs . chmodSync ( dir , '777' )
1610+ restorePermissions ( dir )
1611+ }
1612+
1613+ function removePermissions ( dir ) {
1614+ if ( process . platform === 'win32' ) {
1615+ execSync ( `icacls ${ dir } /deny "everyone:R"` )
1616+ return 'EPERM' ;
1617+ }
1618+
1619+ fs . chmodSync ( dir , '000' )
1620+ return 'EACCES'
1621+ }
1622+
1623+ function restorePermissions ( dir ) {
1624+ if ( process . platform === 'win32' ) {
1625+ execSync ( `icacls ${ dir } /grant "everyone:R"` )
1626+ } else {
1627+ fs . chmodSync ( dir , '777' )
1628+ }
16111629 }
16121630 } )
16131631} )
0 commit comments