Comments (8)
So looks like it can be reproduced (on my machine) with:
const readdirEnhanced = require('@mrmlnc/readdir-enhanced')
readdirEnhanced.readdirSync('/dev/fd')
Throws:
Error: EBADF: bad file descriptor, lstat '/dev/fd/12'
at Object.fs.lstatSync (fs.js:941:11)
at exports.lstat (xxx/node_modules/.registry.npmjs.org/@mrmlnc/readdir-enhanced/2.2.1/node_modules/@mrmlnc/readdir-enhanced/lib/sync/fs.js:59:20)
at Object.safeCall [as safe] (xxx/node_modules/.registry.npmjs.org/@mrmlnc/readdir-enhanced/2.2.1/node_modules/@mrmlnc/readdir-enhanced/lib/call.js:24:8)
at stat (xxx/node_modules/.registry.npmjs.org/@mrmlnc/readdir-enhanced/2.2.1/node_modules/@mrmlnc/readdir-enhanced/lib/stat.js:19:8)
at DirectoryReader.processItem (xxx/node_modules/.registry.npmjs.org/@mrmlnc/readdir-enhanced/2.2.1/node_modules/@mrmlnc/readdir-enhanced/lib/directory-reader.js:178:5)
at array.forEach.item (xxx/node_modules/.registry.npmjs.org/@mrmlnc/readdir-enhanced/2.2.1/node_modules/@mrmlnc/readdir-enhanced/lib/sync/for-each.js:14:5)
at Array.forEach (<anonymous>)
at Object.syncForEach [as forEach] (xxx/node_modules/.registry.npmjs.org/@mrmlnc/readdir-enhanced/2.2.1/node_modules/@mrmlnc/readdir-enhanced/lib/sync/for-each.js:13:9)
at call.safe (xxx/node_modules/.registry.npmjs.org/@mrmlnc/readdir-enhanced/2.2.1/node_modules/@mrmlnc/readdir-enhanced/lib/directory-reader.js:87:16)
at onceWrapper (xxx/node_modules/.registry.npmjs.org/@mrmlnc/readdir-enhanced/2.2.1/node_modules/@mrmlnc/readdir-enhanced/lib/call.js:45:17)
at onceWrapper (xxx/node_modules/.registry.npmjs.org/@mrmlnc/readdir-enhanced/2.2.1/node_modules/@mrmlnc/readdir-enhanced/lib/call.js:45:17)
at exports.readdir (xxx/node_modules/.registry.npmjs.org/@mrmlnc/readdir-enhanced/2.2.1/node_modules/@mrmlnc/readdir-enhanced/lib/sync/fs.js:19:5)
at Object.safeCall [as safe] (xxx/node_modules/.registry.npmjs.org/@mrmlnc/readdir-enhanced/2.2.1/node_modules/@mrmlnc/readdir-enhanced/lib/call.js:24:8)
at DirectoryReader.readNextDirectory (xxx/node_modules/.registry.npmjs.org/@mrmlnc/readdir-enhanced/2.2.1/node_modules/@mrmlnc/readdir-enhanced/lib/directory-reader.js:78:10)
at Readable.DirectoryReader.stream._read (xxx/node_modules/.registry.npmjs.org/@mrmlnc/readdir-enhanced/2.2.1/node_modules/@mrmlnc/readdir-enhanced/lib/directory-reader.js:57:18)
at Readable.read (_stream_readable.js:442:10)
at readdirSync (xxx/node_modules/.registry.npmjs.org/@mrmlnc/readdir-enhanced/2.2.1/node_modules/@mrmlnc/readdir-enhanced/lib/sync/index.js:27:21)
at Function.readdirSyncStat (xxx/node_modules/.registry.npmjs.org/@mrmlnc/readdir-enhanced/2.2.1/node_modules/@mrmlnc/readdir-enhanced/lib/index.js:34:10)
at ReaderSync.api (xxx/node_modules/.registry.npmjs.org/fast-glob/2.0.4/node_modules/fast-glob/out/providers/reader-sync.js:25:24)
at ReaderSync.read (xxx/node_modules/.registry.npmjs.org/fast-glob/2.0.4/node_modules/fast-glob/out/providers/reader-sync.js:35:32)
at Array.map (<anonymous>)
at getWorks (xxx/node_modules/.registry.npmjs.org/fast-glob/2.0.4/node_modules/fast-glob/out/index.js:18:18)
at Function.sync (xxx/node_modules/.registry.npmjs.org/fast-glob/2.0.4/node_modules/fast-glob/out/index.js:24:17)
at Test.fn (xxx/index.test.js:25:18)
at Test.callFn (xxx/node_modules/.registry.npmjs.org/ava/0.23.0/node_modules/ava/lib/test.js:305:18)
at Test.run (xxx/node_modules/.registry.npmjs.org/ava/0.23.0/node_modules/ava/lib/test.js:318:23)
at runNext (xxx/node_modules/.registry.npmjs.org/ava/0.23.0/node_modules/ava/lib/sequence.js:58:44)
at Sequence.run (xxx/node_modules/.registry.npmjs.org/ava/0.23.0/node_modules/ava/lib/sequence.js:90:10)
at Concurrent.run (xxx/node_modules/.registry.npmjs.org/ava/0.23.0/node_modules/ava/lib/concurrent.js:41:37)
at runNext (xxx/node_modules/.registry.npmjs.org/ava/0.23.0/node_modules/ava/lib/sequence.js:58:44)
at Sequence.run (xxx/node_modules/.registry.npmjs.org/ava/0.23.0/node_modules/ava/lib/sequence.js:90:10)
at runNext (xxx/node_modules/.registry.npmjs.org/ava/0.23.0/node_modules/ava/lib/sequence.js:58:44)
at Sequence.run (xxx/node_modules/.registry.npmjs.org/ava/0.23.0/node_modules/ava/lib/sequence.js:90:10)
at Bluebird.try (xxx/node_modules/.registry.npmjs.org/ava/0.23.0/node_modules/ava/lib/runner.js:224:48)
at tryCatcher (xxx/node_modules/.registry.npmjs.org/bluebird/3.5.1/node_modules/bluebird/js/release/util.js:16:23)
at Function.Promise.attempt.Promise.try (xxx/node_modules/.registry.npmjs.org/bluebird/3.5.1/node_modules/bluebird/js/release/method.js:39:29)
at Runner.run (xxx/node_modules/.registry.npmjs.org/ava/0.23.0/node_modules/ava/lib/runner.js:224:22)
at process.on.options (xxx/node_modules/.registry.npmjs.org/ava/0.23.0/node_modules/ava/lib/main.js:84:10)
at emitOne (events.js:116:13)
at process.emit (events.js:211:7)
at process.on.message (xxx/node_modules/.registry.npmjs.org/ava/0.23.0/node_modules/ava/lib/process-adapter.js:14:10)
at emitTwo (events.js:126:13)
at process.emit (events.js:214:7)
at emit (internal/child_process.js:772:12)
at _combinedTickCallback (internal/process/next_tick.js:141:11)
at process._tickCallback (internal/process/next_tick.js:180:9) errno: -9, code: 'EBADF', syscall: 'lstat', path: '/dev/fd/12' } }
$ ls -al /dev/fd
dr-xr-xr-x 1 root wheel 0 15 Feb 15:26 .
dr-xr-xr-x 3 root wheel 7075 15 Feb 15:26 ..
crw--w---- 1 Me tty 16, 30 17 Feb 11:49 0
crw--w---- 1 Me tty 16, 30 17 Feb 11:49 1
crw--w---- 1 Me tty 16, 30 17 Feb 11:49 2
dr--r--r-- 1 root wheel 0 15 Feb 15:26 4
This doesn't involve any memfs/unionfs stuff from above.
from fast-glob.
Using zsh autocompletion:
~ ls /dev/fd/
0% 1% 10% 11% 12 2% 3
Using ls:
~ ls /dev/fd
0 1 2 4
Maybe the additional fd
links are creating inside the running process...
https://unix.stackexchange.com/questions/74454/somethings-special-about-dev-fd-3
from fast-glob.
Hello, @vjpr,
Thanks for reporting! I'll take a look at it very soon.
from fast-glob.
So, I see that your issue has a two problems (EBADF
and code sample). Sorry, but I don't fully understand your problems. Please use GitHub Issue template for clarifying your problem.
EBADF
What is happening?
Why readdirSync
works?
Because fs.readdirSync
just reads the catalog and doesn't try to read the items inside it.
Why readdir-enhanced
works?
Because it works like fs.readdirSync
without { deep: true }
option. Inside fast-glob
we use deep
option.
Why glob
works?
Because glob
first tries to understand what he's dealing with. Related issue that will help to fix this problem:
Why fast-glob
doesn't it work?
Inside fast-glob
we use deep: true
option and try to look inside the directories. When we try to get lstat
or stat
it throws error.
Questions
- What's the expected behavior here?
Code sample
fs.writeFileSync('/app/foo.json', 'foo')
// Results
glob.sync('/app') // ['/app']
fg.sync('/app') // [] Because we don't read entries inside directory (will be fixed by #47)
fs.writeFileSync('/app/foo.json', 'foo')
fs.symlinkSync('/app', '/app/foo')
// Results
glob.sync('/app') // ['/app']
fg.sync('/app') // [] Because we don't read entries inside directory (will be fixed by #47)
glob.sync('./app/**'); // [ 'app', 'app/foo', 'app/foo.json' ]
fg.sync('./app/**', { onlyFiles: false }); // [ 'app/foo', 'app/foo.json' ]
Questions
- What's the expected behavior here?
from fast-glob.
What about:
console.log(glob.sync('/app/foo/*')) // ? ['/app/foo/foo.json']
console.log(fg.sync('/app/foo/*')) // ? []
They should return the same.
from fast-glob.
Original FS:
const fs = require('fs');
const glob = require('glob');
const fg = require('fast-glob');
const re = require('readdir-enhanced');
fs.mkdirpSync('./app');
fs.writeFileSync('./app/foo.json', 'foo')
fs.symlinkSync('./app', './app/foo')
console.log('fs', fs.readdirSync('./app'));
console.log('glob', glob.sync('./app/*'));
console.log('re', re.sync('./app'));
console.log('fg', fg.sync('./app/*'));
// fs [ 'foo', 'foo.json' ]
// glob [ './app/foo', './app/foo.json' ]
// re [ 'foo', 'foo.json' ]
// fg [ './app/foo.json' ]
VFS:
const fs = require('fs');
const { Volume } = require('memfs');
const { patchFs } = require('fs-monkey');
const { ufs } = require('unionfs');
const glob = require('glob');
const fg = require('fast-glob');
const re = require('readdir-enhanced');
function start() {
vol = new Volume()
ufs.use(fs).use(vol);
patchFs(ufs)
}
start()
vol.mkdirpSync('./app');
vol.writeFileSync('./app/foo.json', 'foo')
vol.symlinkSync('./app', './app/foo')
console.log('fs', vol.readdirSync('./app'));
console.log('glob', glob.sync('./app/*'));
console.log('re', re.sync('./app'));
console.log('fg', fg.sync('./app/*'));
// fs [ 'foo', 'foo.json' ]
// glob [ './app/foo', './app/foo.json' ]
// re [ 'foo', 'foo.json' ]
// Maximum call stack size exceeded
// From `node_modules/unionfs/lib/union.js`
from fast-glob.
@streamich Seems like memfs
gets stuck in an infinite loop when reading a dir containing a symlink to itself. Original fs as seen above handles this case with no problem.
E.g.
/app
/app/foo -> /app
from fast-glob.
I'm closing this issue.
The problem with deep reading will be solved in #60.
Feel free to create separate issues for your problems using the GitHub Issue template (env & actual & expected).
from fast-glob.
Related Issues (20)
- fastGlob("?/*") fails to match HOT 1
- How much parallelism does this package uses? HOT 1
- poor performance with large directory in tree (even when ignored) HOT 5
- The `fixtures/{first,}/*` pattern returns incorrect results HOT 2
- Release v3.3.0 [xx.06.2023] HOT 1
- Provide `glob`, `globSync` and `globSteam` aliases HOT 1
- `glob` method errors in the latest release HOT 1
- TypeError: patterns.reduce is not a function HOT 10
- Breaking changes in v3.3.0 HOT 1
- Type definitions erroneously disallow passing an explicitly readonly array of strings HOT 1
- Use `os.availableParallelism` instead of `os.cpus().length` when available HOT 1
- Merging DEFAULT_FILE_SYSTEM_ADAPTER to fs HOT 4
- Regression in v3.3.1 HOT 3
- Case sensitive file paths are returned as potentially the wrong case when using WSL with window's paths HOT 1
- Inconsistent File Format Handling Between Windows and POSIX in fast-glob HOT 7
- Unable to match correctly HOT 1
- fast glob ramdisk issue
- [doc] what is the behaviour of passing an array of patterns?
- Allow abort glob progress
- In Node.js v20.11.0, it's not possible to match directories containing emojis.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fast-glob.