memfs icon indicating copy to clipboard operation
memfs copied to clipboard

Files can incorrectly be nested inside other files

Open SnirBroshi opened this issue 1 year ago • 3 comments

It's possible to read/write files nested inside other files:

const { fs } = require('memfs');
fs.writeFileSync('/foo', 'hello');
fs.writeFileSync('/foo/bar', 'world');
console.log(fs.readFileSync('/foo', 'utf8')); // logs 'hello'
console.log(fs.readFileSync('/foo/bar', 'utf8')); // logs 'world'
console.log(fs.statSync('/foo').isFile()); // logs 'true'
console.log(fs.statSync('/foo').isDirectory()); // logs 'false'
console.log(fs.readdirSync('/foo')); // throws ENOTDIR

/foo is a regular file, and bar is also a regular file that's nested in /foo.

Tested with v4.11.1

SnirBroshi avatar Aug 02 '24 22:08 SnirBroshi

Yup that's a bug alright

G-Rath avatar Aug 02 '24 22:08 G-Rath

Hi @NotWearingPants, I think I may be able to help with this issue. I would love to be assigned to it if possible!

Kenny4297 avatar Aug 03 '24 18:08 Kenny4297

@Kenny4297 go for it!

G-Rath avatar Aug 03 '24 23:08 G-Rath

@G-Rath This is fixed in 4.12.0. This issue can be closed now, as well as #1052.

BadIdeaException avatar Oct 11 '24 06:10 BadIdeaException

@BadIdeaException do you know if we've got a test to guard against future regression?

G-Rath avatar Oct 12 '24 01:10 G-Rath

Yes, we do: openSync.test.ts tests this exact scenario.

BadIdeaException avatar Oct 13 '24 15:10 BadIdeaException

(For future reference: this issue was fixed by #1059)

SnirBroshi avatar Oct 14 '24 00:10 SnirBroshi