Closed warpdesign closed 4 years ago
I created a directory with mode 0o000. When using node's fs.readdir, an error with code EACCES is thrown but when mocked, it succeeds with ['0'] as result.
0o000
fs.readdir
EACCES
['0']
I am using OSX Catalina.
Code to reproduce the problem:
const mock = require('mock-fs'); const fs = require('fs'); const util = require('util'); console.log(''); try { fs.rmdirSync('/tmp/denied'); } catch(e) { } fs.mkdirSync('/tmp/denied', 0o000); const mockFs = () => { mock({ ['/tmp/denied']: mock.directory({ mode: 0o000, items: [ { file: 'file' } ] }) }); } const read = async (shouldMock) => { if (shouldMock) { console.log('mocked fs'); console.log('========='); mockFs(); } else { console.log('native fs'); console.log('========='); } try { const files = await util.promisify(fs.readdir)('/tmp/denied'); console.log('success', files); } catch(err) { console.log('error', err.code); } } async function test() { await read(false); console.log(''); await read(true); } test();
When running it on a terminal, I get the following output:
native fs ======== error EACCES mocked fs ======== success [ '0' ]
Node.js version: 12.14.1 mock-fs version: 4.11.0
12.14.1
4.11.0
Fix published in mock-fs@4.12.0. Thanks, @warpdesign.
mock-fs@4.12.0
I created a directory with mode
0o000
. When using node'sfs.readdir
, an error with codeEACCES
is thrown but when mocked, it succeeds with['0']
as result.I am using OSX Catalina.
Code to reproduce the problem:
When running it on a terminal, I get the following output:
Node.js version:
12.14.1
mock-fs version:4.11.0