Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENOENT: no such file or directory, scandir #240

Closed
l1bbcsg opened this issue Mar 6, 2019 · 2 comments · Fixed by #348
Closed

ENOENT: no such file or directory, scandir #240

l1bbcsg opened this issue Mar 6, 2019 · 2 comments · Fixed by #348
Labels

Comments

@l1bbcsg
Copy link

l1bbcsg commented Mar 6, 2019

This regression was introduced in 4.2.0
4.1.0 and prior work as expected.
Node version is v10.12.0

Sample code:

const realFs = require('fs');
const virtualFs = new (require('memfs').Volume)();
const unionFs = new (require('unionfs').Union)();

virtualFs.fromJSON({
	'does-not-exist-in-real-fs/file.txt': ''
});

unionFs.use(virtualFs);
unionFs.use(realFs);

try { console.log('realFs',    realFs.readdirSync('does-not-exist-in-real-fs'));    } catch(e) {console.error(e.message)}
try { console.log('virtualFs', virtualFs.readdirSync('does-not-exist-in-real-fs')); } catch(e) {console.error(e.message)}
try { console.log('unionFs',   unionFs.readdirSync('does-not-exist-in-real-fs'));   } catch(e) {console.error(e.message)}

Expected result:

Directory can be read in virtual fs, union fs but not real fs.

ENOENT: no such file or directory, scandir 'does-not-exist-in-real-fs'
virtualFs [ 'file.txt' ]
unionFs [ 'file.txt' ]

Actual result:

Directory can be read in virtual fs, but not union fs and real fs.

ENOENT: no such file or directory, scandir 'does-not-exist-in-real-fs'
virtualFs [ 'file.txt' ]
ENOENT: no such file or directory, scandir 'does-not-exist-in-real-fs'
@Sleepful
Copy link

Sleepful commented Mar 15, 2019

Same issue, readdirSync('/') does actually work, but once I try any path other than / it crashes with

node_modules\unionfs\lib\union.js:233
                    throw err;
                    ^

Error: ENOENT: no such file or directory, scandir '/dist'

even though I can read the files in those paths like so ufs.readFileSync('/src/index.html', 'utf8')

I also tried to downgrade by doing npm install unionfs@4.1.0 but I still have the same issue, however in previous versions the issue exists only when accessing memfs filesystem, in the previous versions I can access the system's fs filesystem. In latest version both give errors.


Quick Fix

Comment out line 288 in node_modules\unionfs\lib\union.js (this is the line in the .ts), I believe this throws an error when it fails to find a directory in one filesystem and then it stops trying to find it on the other filesystems, if you comment out the line: throw err below if (!i) { // last one then it finds the directory but it won't throw error if the directory doesn't exist in any of the filesystems

magarcia added a commit to magarcia/unionfs that referenced this issue Oct 17, 2019
* `readdirSync` throws `ENOENT: no such file or directory, scandir` when
   the directory does not exists one of the file systems.
* Problem solved checking also if there are some results before throw.

Fixes streamich#240
magarcia added a commit to magarcia/unionfs that referenced this issue Oct 17, 2019
* `readdirSync` throws `ENOENT: no such file or directory, scandir` when
   the directory does not exists one of the file systems.
* Problem solved checking also if there are some results before throw.

Fixes streamich#240
streamich pushed a commit that referenced this issue Dec 19, 2019
## [4.2.1](v4.2.0...v4.2.1) (2019-12-19)

### Bug Fixes

* **readdir:** 🐛  Error no such file or directory ([8d21e9a](8d21e9a))
* **readdirSync:** 🐛  Error no such file or directory ([b6c5764](b6c5764)), closes [#240](#240)
@streamich
Copy link
Owner

🎉 This issue has been resolved in version 4.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants