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

Using a file as a directory throws ENOENT instead of ENOTDIR #1050

Open
NotWearingPants opened this issue Aug 2, 2024 · 5 comments
Open

Comments

@NotWearingPants
Copy link

Using memfs:

const { fs } = require('memfs');
fs.writeFileSync('/foo', 'hello');
fs.readFileSync('/foo/bar'); // throws ENOENT

Using the builtin fs (on Linux):

const fs = require('node:fs');
fs.writeFileSync('/foo', 'hello');
fs.readFileSync('/foo/bar'); // throws ENOTDIR

Using the builtin fs (on Windows):

const fs = require('node:fs');
fs.writeFileSync('C:/foo', 'hello');
fs.readFileSync('C:/foo/bar'); // throws ENOENT

I'm not sure which behavior makes more sense and if this difference is a bug in Node.js, but I think that if !isWin then memfs should also throw ENOTDIR.

@G-Rath
Copy link
Collaborator

G-Rath commented Aug 2, 2024

Can you mention what version of Node you're using? As I suspect this might have been something that changed - note too we don't aim to 1:1 match the behaviour of Node especially in regards to error codes due to the potential number of differences across both Node majors and OSs, but this one seems like it should be straightforward to support.

@NotWearingPants
Copy link
Author

I tested this with memfs v4.11.1 and Node.js v20.12.2

@BadIdeaException
Copy link
Contributor

@G-Rath This is fixed in 4.12.0. This issue can be closed now.

@G-Rath
Copy link
Collaborator

G-Rath commented Oct 12, 2024

@BadIdeaException do you know if we've got a test to ensure this doesn't regress in the future?

It looks like we might have actually have a test that verifies the opposite error than what we want here? But I'm on mobile so might have missed something 😅

@BadIdeaException
Copy link
Contributor

Hmm, you're right. I didn't read closely enough. This is only fixed for creating a file, where openSync.test.ts tests that the correct error is thrown. (NB: mkdirSync.test.ts tests the analogous case when trying to create a directory under a file, at least in recursive mode.)

When trying to read from an illegally nested file, I am still seeing ENOENT, just like OP said.

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

No branches or pull requests

3 participants